diff --git a/app/build.gradle b/app/build.gradle index 3c14510..f19ec67 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,6 +31,7 @@ repositories { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:preference-v7:27.1.1' implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:design:27.1.1' implementation 'com.android.support:support-v4:27.1.1' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 54170df..ed85fed 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,7 +10,6 @@ - @@ -45,18 +44,16 @@ android:label="@string/title_activity_login" android:launchMode="singleTask" android:noHistory="true" /> - + android:exported="false" + android:launchMode="singleTop" /> - + \ No newline at end of file diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java index 839f673..5a55012 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java @@ -2,6 +2,7 @@ package com.uam.wmi.findmytutor.activity; import android.annotation.SuppressLint; import android.app.Activity; +import android.app.FragmentTransaction; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -9,6 +10,7 @@ import android.os.Build; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; +import android.preference.PreferenceCategory; import android.preference.PreferenceFragment; import android.util.Log; import android.view.LayoutInflater; @@ -43,14 +45,31 @@ public class SharingFragment extends PreferenceFragment { locationLevelMapping.put(0,"presence"); locationLevelMapping.put(1,"approximated"); locationLevelMapping.put(2,"exact"); + locationLevelMapping.put(3,"manual"); addPreferencesFromResource(R.layout.pref_sharing); Preference manualStatus = findPreference("key_manual_status"); Preference locationSharing = findPreference("key_sharing_enabled"); Preference locationMode = findPreference("key_location_level"); Preference statusList = findPreference("key_status_value"); - - + Preference manualLocationList = findPreference("key_manual_location_value"); + Preference manualLocationButton = findPreference("manual_location_button"); + PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("category_sharing"); + String temp = PrefUtils.getLocationLevel(getApplicationContext()); + if(!temp.equals("manual")){ + preferenceCategory.removePreference(manualLocationList); + preferenceCategory.removePreference(manualLocationButton); + } + manualLocationButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Toast.makeText(getApplicationContext(), "dupa", Toast.LENGTH_SHORT).show(); + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + fragmentTransaction.hide(SharingFragment.this); + fragmentTransaction.commit(); + return true; + } + }); manualStatus.setOnPreferenceChangeListener((preference, newValue) -> { ListPreference lp = (ListPreference) findPreference("key_status_value"); updateListPreference(lp, newValue, "manual_statuses"); @@ -62,6 +81,14 @@ public class SharingFragment extends PreferenceFragment { locationMode.setOnPreferenceChangeListener((preference, newValue) -> { ListPreference lp = (ListPreference) preference; PrefUtils.storeLocationMode(getApplicationContext(),locationLevelMapping.get(Integer.parseInt((String) newValue))); + if(PrefUtils.getLocationLevel(getApplicationContext()) == "manual"){ + preferenceCategory.addPreference(manualLocationList); + preferenceCategory.addPreference(manualLocationButton); + + }else{ + preferenceCategory.removePreference(manualLocationList); + preferenceCategory.removePreference(manualLocationButton); + } return true; }); @@ -77,6 +104,7 @@ public class SharingFragment extends PreferenceFragment { ((MapActivity)getActivity()).handleBackgroundTaskLifeCycle(); return true; }); + } public static SharingFragment newInstance() { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/rightButtonPreference.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/rightButtonPreference.java new file mode 100644 index 0000000..8d63618 --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/rightButtonPreference.java @@ -0,0 +1,44 @@ +package com.uam.wmi.findmytutor.utils; + +import android.content.Context; + +import android.preference.Preference; +import android.support.v7.preference.PreferenceViewHolder; +import android.util.AttributeSet; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; + + +import com.uam.wmi.findmytutor.R; + +public class rightButtonPreference extends Preference { + public rightButtonPreference(Context context, AttributeSet attrs) { + super(context, attrs); +// setLayoutResource(R.layout.preference_button_widget); + } + + @Override + protected View onCreateView(ViewGroup parent) { + View view = super.onCreateView(parent); + LayoutInflater li = (LayoutInflater)getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE ); + return li.inflate( R.layout.preference_button_widget, parent, false); + } + +/* @Override + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); + holder.itemView.setClickable(false); // disable parent click + View button = holder.findViewById(R.id.theme_dark); + button.setClickable(true); // enable custom view click + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + } + }); + }*/ +} diff --git a/app/src/main/res/layout/pref_sharing.xml b/app/src/main/res/layout/pref_sharing.xml index 95817ac..4d681ce 100644 --- a/app/src/main/res/layout/pref_sharing.xml +++ b/app/src/main/res/layout/pref_sharing.xml @@ -6,7 +6,9 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + + + @@ -45,26 +57,6 @@ /> - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/preference_button_widget.xml b/app/src/main/res/layout/preference_button_widget.xml new file mode 100644 index 0000000..ad78053 --- /dev/null +++ b/app/src/main/res/layout/preference_button_widget.xml @@ -0,0 +1,13 @@ + + +