forked from github/wulkanowy-mirror
Add about section in settings (#99)
This commit is contained in:

committed by
Rafał Borcz

parent
dd2c69601a
commit
f29689c6cd
@ -165,9 +165,7 @@ public class Exam implements Serializable {
|
||||
myDao.update(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* called by internal mechanisms, do not call yourself.
|
||||
*/
|
||||
/** called by internal mechanisms, do not call yourself. */
|
||||
@Generated(hash = 1730563422)
|
||||
public void __setDaoSession(DaoSession daoSession) {
|
||||
this.daoSession = daoSession;
|
||||
|
@ -0,0 +1,67 @@
|
||||
package io.github.wulkanowy.ui.main.settings;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity;
|
||||
|
||||
import io.github.wulkanowy.BuildConfig;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.utils.AppConstant;
|
||||
|
||||
public class AboutScreen extends SettingsFragment {
|
||||
|
||||
public static final String SHARED_KEY_ABOUT_VERSION = "about_version";
|
||||
|
||||
public static final String SHARED_KEY_ABOUT_LICENSES = "about_osl";
|
||||
|
||||
public static final String SHARED_KEY_ABOUT_REPO = "about_repo";
|
||||
|
||||
private Preference.OnPreferenceClickListener onProgrammerListener = new Preference.OnPreferenceClickListener() {
|
||||
private int clicks = 0;
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Toast.makeText(getActivity(), getVersionToast(clicks++), Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getVersionToast(int click) {
|
||||
if (0 == click) {
|
||||
return R.string.about_programmer_step1;
|
||||
}
|
||||
|
||||
if (1 == click) {
|
||||
return R.string.about_programmer_step2;
|
||||
}
|
||||
|
||||
if (9 > click) {
|
||||
return R.string.about_programmer_step3;
|
||||
}
|
||||
|
||||
return R.string.about_programmer;
|
||||
}
|
||||
};
|
||||
|
||||
public AboutScreen() {
|
||||
// silence is golden
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
findPreference(SHARED_KEY_ABOUT_VERSION).setSummary(BuildConfig.VERSION_NAME);
|
||||
findPreference(SHARED_KEY_ABOUT_VERSION).setOnPreferenceClickListener(onProgrammerListener);
|
||||
findPreference(SHARED_KEY_ABOUT_REPO).setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(AppConstant.REPO_URL)));
|
||||
findPreference(SHARED_KEY_ABOUT_LICENSES).setIntent(new Intent(getActivity(), OssLicensesMenuActivity.class)
|
||||
.putExtra("title", getString(R.string.pref_about_osl)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle bundle, String rootKey) {
|
||||
setPreferencesFromResource(R.xml.preferences, rootKey);
|
||||
}
|
||||
}
|
@ -2,13 +2,17 @@ package io.github.wulkanowy.ui.main.settings;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.services.jobs.SyncJob;
|
||||
|
||||
public class SettingsFragment extends PreferenceFragmentCompat
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
||||
PreferenceFragmentCompat.OnPreferenceStartScreenCallback{
|
||||
|
||||
public static final String SHARED_KEY_START_TAB = "startup_tab";
|
||||
|
||||
@ -29,6 +33,31 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getCallbackFragment() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceStartScreen(PreferenceFragmentCompat preferenceFragmentCompat,
|
||||
PreferenceScreen preferenceScreen) {
|
||||
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
|
||||
AboutScreen fragment = new AboutScreen();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.getKey());
|
||||
fragment.setArguments(args);
|
||||
ft.add(R.id.main_activity_container, fragment, preferenceScreen.getKey());
|
||||
ft.addToBackStack(preferenceScreen.getKey());
|
||||
ft.commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (key.equals(SHARED_KEY_SERVICES_ENABLE) || key.equals(SHARED_KEY_SERVICES_INTERVAL)
|
||||
|
@ -19,6 +19,8 @@ public final class AppConstant {
|
||||
|
||||
public static final String DATE_PATTERN = "yyyy-MM-dd";
|
||||
|
||||
public static final String REPO_URL = "https://github.com/wulkanowy/wulkanowy";
|
||||
|
||||
private AppConstant() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
Reference in New Issue
Block a user