2018-02-20 13:54:18 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Anthony Chomienne, anthony@mob-dev.fr
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 3
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.eu.exodus_privacy.exodusprivacy;
|
|
|
|
|
2019-06-06 23:50:53 +02:00
|
|
|
import android.content.pm.PackageInfo;
|
|
|
|
import android.content.pm.PackageManager;
|
2018-04-14 09:46:03 +02:00
|
|
|
import android.support.v4.app.FragmentManager;
|
2018-04-14 14:37:51 +02:00
|
|
|
import android.content.Context;
|
2019-06-04 11:23:27 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.net.Uri;
|
2018-04-11 15:27:05 +02:00
|
|
|
import android.databinding.DataBindingUtil;
|
2018-02-20 13:54:18 +01:00
|
|
|
import android.support.design.widget.Snackbar;
|
2018-04-14 09:46:03 +02:00
|
|
|
import android.support.v4.app.FragmentTransaction;
|
2018-02-20 13:54:18 +01:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
import android.os.Bundle;
|
2019-06-04 11:23:27 +02:00
|
|
|
import android.provider.Settings;
|
2018-04-14 14:37:51 +02:00
|
|
|
import android.support.v7.widget.SearchView;
|
|
|
|
import android.view.Menu;
|
2019-06-04 11:23:27 +02:00
|
|
|
import android.view.MenuItem;
|
2018-04-14 14:37:51 +02:00
|
|
|
import android.view.MenuInflater;
|
2018-04-14 15:29:39 +02:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2018-02-20 13:54:18 +01:00
|
|
|
|
|
|
|
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationListAdapter;
|
2018-04-11 15:27:05 +02:00
|
|
|
import org.eu.exodus_privacy.exodusprivacy.databinding.MainBinding;
|
2018-02-20 13:54:18 +01:00
|
|
|
import org.eu.exodus_privacy.exodusprivacy.fragments.AppListFragment;
|
|
|
|
import org.eu.exodus_privacy.exodusprivacy.fragments.ReportFragment;
|
|
|
|
import org.eu.exodus_privacy.exodusprivacy.listener.NetworkListener;
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
2019-06-04 11:23:27 +02:00
|
|
|
private AppListFragment appList;
|
|
|
|
private ReportFragment report;
|
|
|
|
private SearchView searchView;
|
|
|
|
private Menu toolbarMenu;
|
|
|
|
private MenuItem settingsMenuItem;
|
|
|
|
private String packageName;
|
|
|
|
private MainBinding binding;
|
2018-02-20 13:54:18 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2019-06-04 11:23:27 +02:00
|
|
|
binding = DataBindingUtil.setContentView(this,R.layout.main);
|
|
|
|
final MainBinding mainBinding = binding;
|
2018-02-20 13:54:18 +01:00
|
|
|
|
|
|
|
NetworkListener networkListener = new NetworkListener() {
|
|
|
|
@Override
|
|
|
|
public void onSuccess() {
|
|
|
|
runOnUiThread(() -> {
|
|
|
|
appList.updateComplete();
|
|
|
|
if(report != null)
|
2018-04-11 15:27:05 +02:00
|
|
|
report.updateComplete();
|
2018-02-20 13:54:18 +01:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(String error) {
|
|
|
|
runOnUiThread(() -> {
|
|
|
|
appList.updateComplete();
|
2018-04-11 15:27:05 +02:00
|
|
|
Snackbar bar = Snackbar.make(mainBinding.fragmentContainer,error,Snackbar.LENGTH_LONG);
|
2018-02-20 13:54:18 +01:00
|
|
|
bar.show();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onProgress(int resourceId, int progress, int maxProgress) {
|
|
|
|
//do nothing here
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-06 23:50:53 +02:00
|
|
|
ApplicationListAdapter.OnAppClickListener onAppClickListener = vm -> {
|
|
|
|
try {
|
|
|
|
PackageManager pm = getPackageManager();
|
|
|
|
PackageInfo packageInfo = pm.getPackageInfo(vm.packageName, PackageManager.GET_PERMISSIONS);
|
|
|
|
|
|
|
|
report = ReportFragment.newInstance(pm,packageInfo);
|
|
|
|
FragmentManager manager = getSupportFragmentManager();
|
|
|
|
FragmentTransaction transaction = manager.beginTransaction();
|
|
|
|
transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_right, R.anim.slide_in_left, R.anim.slide_out_left)
|
|
|
|
.replace(R.id.fragment_container,report)
|
|
|
|
.addToBackStack(null)
|
|
|
|
.commit();
|
|
|
|
|
|
|
|
packageName = packageInfo.packageName;
|
|
|
|
|
|
|
|
searchView.clearFocus();
|
|
|
|
if (toolbarMenu != null)
|
|
|
|
(toolbarMenu.findItem(R.id.action_filter)).collapseActionView();
|
|
|
|
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
assert imm != null;
|
|
|
|
imm.hideSoftInputFromWindow(mainBinding.fragmentContainer.getWindowToken(), 0);
|
|
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2018-02-20 13:54:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
appList = AppListFragment.newInstance(networkListener,onAppClickListener);
|
|
|
|
|
|
|
|
|
2018-04-14 09:46:03 +02:00
|
|
|
FragmentManager manager = getSupportFragmentManager();
|
2018-02-20 13:54:18 +01:00
|
|
|
FragmentTransaction transaction = manager.beginTransaction();
|
2018-04-14 09:46:03 +02:00
|
|
|
transaction.replace(R.id.fragment_container,appList)
|
|
|
|
.commit();
|
2018-02-20 13:54:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2018-04-14 09:46:03 +02:00
|
|
|
if (getSupportFragmentManager().getBackStackEntryCount() == 0)
|
|
|
|
finish();
|
2019-06-04 11:23:27 +02:00
|
|
|
else {
|
2018-04-14 09:46:03 +02:00
|
|
|
getSupportFragmentManager().popBackStack();
|
2019-06-04 11:23:27 +02:00
|
|
|
report = null;
|
|
|
|
}
|
2018-02-20 13:54:18 +01:00
|
|
|
}
|
2018-04-14 14:37:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
2019-06-04 11:23:27 +02:00
|
|
|
toolbarMenu = menu;
|
2018-04-14 14:37:51 +02:00
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.main, menu);
|
2018-04-14 15:29:39 +02:00
|
|
|
searchView = (SearchView) menu.findItem(R.id.action_filter).getActionView();
|
2018-04-14 14:37:51 +02:00
|
|
|
searchView.setIconifiedByDefault(false);
|
|
|
|
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextSubmit(String query) {
|
|
|
|
appList.filter(query);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextChange(String newText) {
|
|
|
|
appList.filter(newText);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2019-06-04 11:23:27 +02:00
|
|
|
|
|
|
|
settingsMenuItem = menu.findItem(R.id.action_settings);
|
|
|
|
if (report != null)
|
|
|
|
settingsMenuItem.setVisible(true);
|
|
|
|
else
|
|
|
|
settingsMenuItem.setVisible(false);
|
2018-04-14 14:37:51 +02:00
|
|
|
return true;
|
|
|
|
}
|
2019-06-04 11:23:27 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
if(item.getItemId() == R.id.action_settings) {
|
|
|
|
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
|
|
intent.setData(Uri.fromParts("package",packageName,null));
|
|
|
|
try {
|
|
|
|
startActivity(intent);
|
|
|
|
} catch(android.content.ActivityNotFoundException e) {
|
|
|
|
Snackbar bar = Snackbar.make(binding.fragmentContainer,R.string.no_settings,Snackbar.LENGTH_LONG);
|
|
|
|
bar.show();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-20 13:54:18 +01:00
|
|
|
}
|