use dialog fragment instead of support dialog fragment / use class method for version string
This commit is contained in:
parent
e372fd8b46
commit
0ae67173c5
2 changed files with 15 additions and 30 deletions
|
@ -23,6 +23,7 @@ package de.luhmer.owncloudnewsreader;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -45,7 +46,6 @@ import android.preference.TwoStatePreference;
|
|||
import android.provider.Settings;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.AppCompatCheckBox;
|
||||
import android.support.v7.widget.AppCompatCheckedTextView;
|
||||
|
@ -139,7 +139,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
version = getVersionString();
|
||||
version = VersionInfoDialogFragment.getVersionString(this);
|
||||
ThemeChooser.getInstance(this).chooseTheme(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
ThemeChooser.getInstance(this).afterOnCreate(this);
|
||||
|
@ -215,13 +215,12 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||
header.setTitle(R.string.pref_header_about);
|
||||
getPreferenceScreen().addPreference(header);
|
||||
addPreferencesFromResource(R.xml.pref_about);
|
||||
Preference dialogPreference = (Preference)getPreferenceScreen().findPreference(CB_VERSION);
|
||||
Preference dialogPreference = getPreferenceScreen().findPreference(CB_VERSION);
|
||||
dialogPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
DialogFragment dialog = new VersionInfoDialogFragment();
|
||||
|
||||
//dialog.show(getSupportFragmentManager(), "VersionChangelogDialogFragment");
|
||||
return true;
|
||||
dialog.show(SettingsActivity.this.getFragmentManager(), "VersionChangelogDialogFragment");
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -390,21 +389,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||
preference.getContext()).getBoolean(preference.getKey(), false));
|
||||
}
|
||||
|
||||
private String getVersionString() {
|
||||
String version = "?";
|
||||
|
||||
try {
|
||||
PackageInfo pInfo = this.getPackageManager().getPackageInfo(this.getPackageName(), 0);
|
||||
version = pInfo.versionName;
|
||||
} catch (PackageManager.NameNotFoundException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Formatter formatter = new Formatter();
|
||||
String versionString = getString(R.string.current_version);
|
||||
return formatter.format(versionString, version).toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(String name, Context context, AttributeSet attrs) {
|
||||
|
|
|
@ -21,12 +21,13 @@
|
|||
|
||||
package de.luhmer.owncloudnewsreader;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager.LayoutParams;
|
||||
|
@ -50,9 +51,9 @@ public class VersionInfoDialogFragment extends DialogFragment {
|
|||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
View view = inflater.inflate(R.layout.dialog_version_info, null);
|
||||
|
||||
ChangeLogFileListView clListView = (ChangeLogFileListView) view.findViewById(R.id.changelog_listview);
|
||||
final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.changeLogLoadingProgressBar);
|
||||
TextView versionTextView = (TextView) view.findViewById(R.id.tv_androidAppVersion);
|
||||
ChangeLogFileListView clListView = view.findViewById(R.id.changelog_listview);
|
||||
final ProgressBar progressBar = view.findViewById(R.id.changeLogLoadingProgressBar);
|
||||
TextView versionTextView = view.findViewById(R.id.tv_androidAppVersion);
|
||||
|
||||
// build dialog
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
|
||||
|
@ -60,7 +61,7 @@ public class VersionInfoDialogFragment extends DialogFragment {
|
|||
.setTitle(getString(R.string.menu_About_Changelog));
|
||||
|
||||
// set current version
|
||||
versionTextView.setText(getVersionString());
|
||||
versionTextView.setText(getVersionString(getActivity()));
|
||||
|
||||
// load changelog into view
|
||||
loadChangeLog(clListView, progressBar);
|
||||
|
@ -82,18 +83,18 @@ public class VersionInfoDialogFragment extends DialogFragment {
|
|||
super.onStart();
|
||||
}
|
||||
|
||||
private String getVersionString() {
|
||||
public static String getVersionString(Activity activity) {
|
||||
String version = "?";
|
||||
|
||||
try {
|
||||
PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
|
||||
PackageInfo pInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
|
||||
version = pInfo.versionName;
|
||||
} catch (PackageManager.NameNotFoundException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Formatter formatter = new Formatter();
|
||||
String versionString = getString(R.string.current_version);
|
||||
String versionString = activity.getString(R.string.current_version);
|
||||
return formatter.format(versionString, version).toString();
|
||||
}
|
||||
|
||||
|
@ -101,7 +102,7 @@ public class VersionInfoDialogFragment extends DialogFragment {
|
|||
* Loads changelog into the given view and hides progress bar when done.
|
||||
*/
|
||||
private void loadChangeLog(ChangeLogFileListView clListView, final ProgressBar progressBar) {
|
||||
new DownloadChangelogTask(getContext(), clListView, new DownloadChangelogTask.Listener() {
|
||||
new DownloadChangelogTask(getActivity(), clListView, new DownloadChangelogTask.Listener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
|
|
Loading…
Reference in a new issue