aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui/AboutDialog.java
blob: 994d1bd92eea9d93ae722310ab564cf1ccbca559 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package eu.siacs.conversations.ui;

import android.content.Context;
import android.content.pm.PackageManager;
import android.preference.DialogPreference;
import android.util.AttributeSet;

public class AboutDialog extends DialogPreference {
	public AboutDialog(final Context context, final AttributeSet attrs, final int defStyle) {
		super(context, attrs, defStyle);
		setSummary();
	}

	public AboutDialog(final Context context, final AttributeSet attrs) {
		super(context, attrs);
		setSummary();
	}

	private void setSummary() {
		if (getContext() != null &&getContext().getPackageManager() != null) {
			final String packageName = getContext().getPackageName();
			final String versionName;
			try {
				versionName = getContext().getPackageManager().getPackageInfo(packageName, 0).versionName;
				setSummary("Conversations " + versionName);
			} catch (final PackageManager.NameNotFoundException e) {
				// Using try/catch as part of the logic is sort of like this:
				// https://xkcd.com/292/
			}
		}
	}
}