mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-04 16:25:05 -05:00
Refactor AppsListFragment
This commit is contained in:
parent
2064d81aef
commit
29628e54ec
@ -48,7 +48,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps;
|
|||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
public class AppsListFragment extends ListFragment implements
|
public class AppsListFragment extends ListFragment implements
|
||||||
LoaderManager.LoaderCallbacks<Cursor> {
|
LoaderManager.LoaderCallbacks<Cursor>, OnItemClickListener {
|
||||||
|
|
||||||
AppsAdapter mAdapter;
|
AppsAdapter mAdapter;
|
||||||
|
|
||||||
@ -56,46 +56,7 @@ public class AppsListFragment extends ListFragment implements
|
|||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
getListView().setOnItemClickListener(new OnItemClickListener() {
|
getListView().setOnItemClickListener(this);
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
|
|
||||||
String selectedPackageName = mAdapter.getItemPackageName(position);
|
|
||||||
boolean installed = mAdapter.getItemIsInstalled(position);
|
|
||||||
boolean registered = mAdapter.getItemIsRegistered(position);
|
|
||||||
|
|
||||||
if (installed) {
|
|
||||||
if (registered) {
|
|
||||||
// Edit app settings
|
|
||||||
Intent intent = new Intent(getActivity(), AppSettingsActivity.class);
|
|
||||||
intent.setData(KeychainContract.ApiApps.buildByPackageNameUri(selectedPackageName));
|
|
||||||
startActivity(intent);
|
|
||||||
} else {
|
|
||||||
Intent i;
|
|
||||||
PackageManager manager = getActivity().getPackageManager();
|
|
||||||
try {
|
|
||||||
i = manager.getLaunchIntentForPackage(selectedPackageName);
|
|
||||||
if (i == null) {
|
|
||||||
throw new PackageManager.NameNotFoundException();
|
|
||||||
}
|
|
||||||
// Start like the Android launcher would do
|
|
||||||
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
|
|
||||||
i.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
||||||
startActivity(i);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
Log.e(Constants.TAG, "startApp", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW,
|
|
||||||
Uri.parse("market://details?id=" + selectedPackageName)));
|
|
||||||
} catch (ActivityNotFoundException anfe) {
|
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW,
|
|
||||||
Uri.parse("https://play.google.com/store/apps/details?id=" + selectedPackageName)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// NOTE: No setEmptyText(), we always have the default entries
|
// NOTE: No setEmptyText(), we always have the default entries
|
||||||
|
|
||||||
@ -120,6 +81,45 @@ public class AppsListFragment extends ListFragment implements
|
|||||||
getLoaderManager().restartLoader(0, null, this);
|
getLoaderManager().restartLoader(0, null, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
String selectedPackageName = mAdapter.getItemPackageName(position);
|
||||||
|
boolean installed = mAdapter.getItemIsInstalled(position);
|
||||||
|
boolean registered = mAdapter.getItemIsRegistered(position);
|
||||||
|
|
||||||
|
if (installed) {
|
||||||
|
if (registered) {
|
||||||
|
// Edit app settings
|
||||||
|
Intent intent = new Intent(getActivity(), AppSettingsActivity.class);
|
||||||
|
intent.setData(KeychainContract.ApiApps.buildByPackageNameUri(selectedPackageName));
|
||||||
|
startActivity(intent);
|
||||||
|
} else {
|
||||||
|
Intent i;
|
||||||
|
PackageManager manager = getActivity().getPackageManager();
|
||||||
|
try {
|
||||||
|
i = manager.getLaunchIntentForPackage(selectedPackageName);
|
||||||
|
if (i == null) {
|
||||||
|
throw new PackageManager.NameNotFoundException();
|
||||||
|
}
|
||||||
|
// Start like the Android launcher would do
|
||||||
|
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
|
||||||
|
i.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||||
|
startActivity(i);
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "startApp", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
startActivity(new Intent(Intent.ACTION_VIEW,
|
||||||
|
Uri.parse("market://details?id=" + selectedPackageName)));
|
||||||
|
} catch (ActivityNotFoundException anfe) {
|
||||||
|
startActivity(new Intent(Intent.ACTION_VIEW,
|
||||||
|
Uri.parse("https://play.google.com/store/apps/details?id=" + selectedPackageName)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final String TEMP_COLUMN_NAME = "NAME";
|
private static final String TEMP_COLUMN_NAME = "NAME";
|
||||||
private static final String TEMP_COLUMN_INSTALLED = "INSTALLED";
|
private static final String TEMP_COLUMN_INSTALLED = "INSTALLED";
|
||||||
private static final String TEMP_COLUMN_REGISTERED = "REGISTERED";
|
private static final String TEMP_COLUMN_REGISTERED = "REGISTERED";
|
||||||
|
Loading…
Reference in New Issue
Block a user