Changeset View
Changeset View
Standalone View
Standalone View
app/src/main/java/it/reyboz/bustorino/fragments/SettingsFragment.java
Show All 12 Lines | BusTO - Fragments components | ||||
GNU General Public License for more details. | GNU General Public License for more details. | ||||
You should have received a copy of the GNU General Public License | You should have received a copy of the GNU General Public License | ||||
along with this program. If not, see <http://www.gnu.org/licenses/>. | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
package it.reyboz.bustorino.fragments; | package it.reyboz.bustorino.fragments; | ||||
import android.content.Context; | import android.content.Context; | ||||
import android.content.Intent; | |||||
import android.content.SharedPreferences; | import android.content.SharedPreferences; | ||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.os.Handler; | import android.os.Handler; | ||||
import android.util.Log; | import android.util.Log; | ||||
import android.view.LayoutInflater; | import android.view.LayoutInflater; | ||||
import android.view.View; | import android.view.View; | ||||
import android.view.ViewGroup; | import android.view.ViewGroup; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||
import androidx.lifecycle.Observer; | import androidx.lifecycle.Observer; | ||||
import androidx.preference.*; | import androidx.preference.*; | ||||
import androidx.work.OneTimeWorkRequest; | import androidx.work.OneTimeWorkRequest; | ||||
import androidx.work.WorkInfo; | import androidx.work.WorkInfo; | ||||
import androidx.work.WorkManager; | import androidx.work.WorkManager; | ||||
import it.reyboz.bustorino.ActivityBackup; | |||||
import it.reyboz.bustorino.R; | import it.reyboz.bustorino.R; | ||||
import it.reyboz.bustorino.data.DatabaseUpdate; | import it.reyboz.bustorino.data.DatabaseUpdate; | ||||
import it.reyboz.bustorino.data.GtfsMaintenanceWorker; | import it.reyboz.bustorino.data.GtfsMaintenanceWorker; | ||||
import org.jetbrains.annotations.NotNull; | import org.jetbrains.annotations.NotNull; | ||||
import java.lang.ref.WeakReference; | import java.lang.ref.WeakReference; | ||||
import java.util.HashSet; | import java.util.HashSet; | ||||
import java.util.List; | import java.util.List; | ||||
Show All 40 Lines | public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { | ||||
} | } | ||||
} | } | ||||
//Log.d("BusTO-PrefFrag","startup screen pref is "+startupScreenPref.getValue()); | //Log.d("BusTO-PrefFrag","startup screen pref is "+startupScreenPref.getValue()); | ||||
Preference dbUpdateNow = findPreference("pref_db_update_now"); | Preference dbUpdateNow = findPreference("pref_db_update_now"); | ||||
if (dbUpdateNow!=null) | if (dbUpdateNow!=null) | ||||
dbUpdateNow.setOnPreferenceClickListener( | dbUpdateNow.setOnPreferenceClickListener( | ||||
new Preference.OnPreferenceClickListener() { | preference -> { | ||||
@Override | |||||
public boolean onPreferenceClick(@NonNull Preference preference) { | |||||
//trigger update | //trigger update | ||||
if(getContext()!=null) { | if(getContext()!=null) { | ||||
DatabaseUpdate.requestDBUpdateWithWork(getContext().getApplicationContext(), true, true); | DatabaseUpdate.requestDBUpdateWithWork(getContext().getApplicationContext(), true, true); | ||||
Toast.makeText(getContext(),R.string.requesting_db_update,Toast.LENGTH_SHORT).show(); | Toast.makeText(getContext(),R.string.requesting_db_update,Toast.LENGTH_SHORT).show(); | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
); | |||||
//set click listener on backup item | |||||
final Preference backupPref = findPreference("pref_backup_open"); | |||||
if (backupPref!=null) backupPref.setOnPreferenceClickListener( | |||||
preference -> { | |||||
if(getActivity()!=null){ | |||||
startActivity( new Intent(getActivity().getApplicationContext(), ActivityBackup.class) ); | |||||
return true; | |||||
} else { | |||||
return false; | |||||
} | |||||
} | } | ||||
); | ); | ||||
else { | else { | ||||
Log.e("BusTO-Preferences", "Cannot find db update preference"); | Log.e("BusTO-Preferences", "Cannot find db update preference"); | ||||
} | } | ||||
Preference clearGtfsTrips = findPreference("pref_clear_gtfs_trips"); | Preference clearGtfsTrips = findPreference("pref_clear_gtfs_trips"); | ||||
if (clearGtfsTrips != null) { | if (clearGtfsTrips != null) { | ||||
▲ Show 20 Lines • Show All 111 Lines • Show Last 20 Lines |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register