use of de.robv.android.xposed.installer.repo.Module in project XposedInstaller by rovo89.
the class DownloadDetailsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final Module module = mActivity.getModule();
if (module == null)
return null;
final View view = inflater.inflate(R.layout.download_details, container, false);
TextView title = (TextView) view.findViewById(R.id.download_title);
title.setText(module.name);
TextView author = (TextView) view.findViewById(R.id.download_author);
if (module.author != null && !module.author.isEmpty())
author.setText(getString(R.string.download_author, module.author));
else
author.setText(R.string.download_unknown_author);
TextView description = (TextView) view.findViewById(R.id.download_description);
if (module.description != null) {
if (module.descriptionIsHtml) {
description.setText(RepoParser.parseSimpleHtml(getActivity(), module.description, description));
description.setTransformationMethod(new LinkTransformationMethod(getActivity()));
description.setMovementMethod(LinkMovementMethod.getInstance());
} else {
description.setText(module.description);
}
} else {
description.setVisibility(View.GONE);
}
ViewGroup moreInfoContainer = (ViewGroup) view.findViewById(R.id.download_moreinfo_container);
for (Pair<String, String> moreInfoEntry : module.moreInfo) {
View moreInfoView = inflater.inflate(R.layout.download_moreinfo, moreInfoContainer, false);
TextView txtTitle = (TextView) moreInfoView.findViewById(android.R.id.title);
TextView txtValue = (TextView) moreInfoView.findViewById(android.R.id.message);
txtTitle.setText(moreInfoEntry.first + ":");
txtValue.setText(moreInfoEntry.second);
final Uri link = NavUtil.parseURL(moreInfoEntry.second);
if (link != null) {
txtValue.setTextColor(txtValue.getLinkTextColors());
moreInfoView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NavUtil.startURL(getActivity(), link);
}
});
}
moreInfoContainer.addView(moreInfoView);
}
return view;
}
use of de.robv.android.xposed.installer.repo.Module in project XposedInstaller by rovo89.
the class RepoLoader method downloadAndParseFiles.
private boolean downloadAndParseFiles(List<String> messages) {
// These variables don't need to be atomic, just mutable
final AtomicBoolean hasChanged = new AtomicBoolean(false);
final AtomicInteger insertCounter = new AtomicInteger();
final AtomicInteger deleteCounter = new AtomicInteger();
for (Entry<Long, Repository> repoEntry : mRepositories.entrySet()) {
final long repoId = repoEntry.getKey();
final Repository repo = repoEntry.getValue();
String url = (repo.partialUrl != null && repo.version != null) ? String.format(repo.partialUrl, repo.version) : repo.url;
File cacheFile = getRepoCacheFile(url);
SyncDownloadInfo info = DownloadsUtil.downloadSynchronously(url, cacheFile);
Log.i(XposedApp.TAG, String.format("Downloaded %s with status %d (error: %s), size %d bytes", url, info.status, info.errorMessage, cacheFile.length()));
if (info.status != SyncDownloadInfo.STATUS_SUCCESS) {
if (info.errorMessage != null)
messages.add(info.errorMessage);
continue;
}
InputStream in = null;
RepoDb.beginTransation();
try {
in = new FileInputStream(cacheFile);
if (url.endsWith(".gz"))
in = new GZIPInputStream(in);
RepoParser.parse(in, new RepoParserCallback() {
@Override
public void onRepositoryMetadata(Repository repository) {
if (!repository.isPartial) {
RepoDb.deleteAllModules(repoId);
hasChanged.set(true);
}
}
@Override
public void onNewModule(Module module) {
RepoDb.insertModule(repoId, module);
hasChanged.set(true);
insertCounter.incrementAndGet();
}
@Override
public void onRemoveModule(String packageName) {
RepoDb.deleteModule(repoId, packageName);
hasChanged.set(true);
deleteCounter.decrementAndGet();
}
@Override
public void onCompleted(Repository repository) {
if (!repository.isPartial) {
RepoDb.updateRepository(repoId, repository);
repo.name = repository.name;
repo.partialUrl = repository.partialUrl;
repo.version = repository.version;
} else {
RepoDb.updateRepositoryVersion(repoId, repository.version);
repo.version = repository.version;
}
Log.i(XposedApp.TAG, String.format("Updated repository %s to version %s (%d new / %d removed modules)", repo.url, repo.version, insertCounter.get(), deleteCounter.get()));
}
});
RepoDb.setTransactionSuccessful();
} catch (Throwable t) {
Log.e(XposedApp.TAG, "Cannot load repository from " + url, t);
messages.add(sApp.getString(R.string.repo_load_failed, url, t.getMessage()));
DownloadsUtil.clearCache(url);
} finally {
if (in != null)
try {
in.close();
} catch (IOException ignored) {
}
cacheFile.delete();
RepoDb.endTransation();
}
}
// repositories
return hasChanged.get();
}
use of de.robv.android.xposed.installer.repo.Module in project XposedInstaller by rovo89.
the class ModulesFragment method importModules.
private boolean importModules(File path) {
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
Toast.makeText(getActivity(), R.string.sdcard_not_writable, Toast.LENGTH_LONG).show();
return false;
}
InputStream ips = null;
RepoLoader repoLoader = RepoLoader.getInstance();
List<Module> list = new ArrayList<>();
if (!path.exists()) {
Toast.makeText(getActivity(), getString(R.string.no_backup_found), Toast.LENGTH_LONG).show();
return false;
}
try {
ips = new FileInputStream(path);
} catch (FileNotFoundException e) {
Log.e(XposedApp.TAG, "Could not open " + path, e);
}
if (path.length() == 0) {
Toast.makeText(getActivity(), R.string.file_is_empty, Toast.LENGTH_LONG).show();
return false;
}
try {
assert ips != null;
InputStreamReader ipsr = new InputStreamReader(ips);
BufferedReader br = new BufferedReader(ipsr);
String line;
while ((line = br.readLine()) != null) {
Module m = repoLoader.getModule(line);
if (m == null) {
Toast.makeText(getActivity(), getString(R.string.download_details_not_found, line), Toast.LENGTH_SHORT).show();
} else {
list.add(m);
}
}
br.close();
} catch (ActivityNotFoundException | IOException e) {
Toast.makeText(getActivity(), e.toString(), Toast.LENGTH_SHORT).show();
}
for (Module m : list) {
ModuleVersion mv = null;
for (int i = 0; i < m.versions.size(); i++) {
ModuleVersion mvTemp = m.versions.get(i);
if (mvTemp.relType == ReleaseType.STABLE) {
mv = mvTemp;
break;
}
}
if (mv != null) {
DownloadsUtil.add(getActivity(), m.name, mv.downloadLink, new DownloadsUtil.DownloadFinishedCallback() {
@Override
public void onDownloadFinished(Context context, DownloadsUtil.DownloadInfo info) {
XposedApp.installApk(context, info);
}
}, DownloadsUtil.MIME_TYPES.APK);
}
}
return true;
}
use of de.robv.android.xposed.installer.repo.Module in project XposedInstaller by rovo89.
the class DownloadDetailsSettingsFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Module module = mActivity.getModule();
if (module == null)
return;
final String packageName = module.packageName;
PreferenceManager prefManager = getPreferenceManager();
prefManager.setSharedPreferencesName("module_settings");
PrefixedSharedPreferences.injectToPreferenceManager(prefManager, module.packageName);
addPreferencesFromResource(R.xml.module_prefs);
SharedPreferences prefs = getActivity().getSharedPreferences("module_settings", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
if (prefs.getBoolean("no_global", true)) {
for (Map.Entry<String, ?> k : prefs.getAll().entrySet()) {
if (prefs.getString(k.getKey(), "").equals("global")) {
editor.putString(k.getKey(), "").apply();
}
}
editor.putBoolean("no_global", false).apply();
}
findPreference("release_type").setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
RepoLoader.getInstance().setReleaseTypeLocal(packageName, (String) newValue);
return true;
}
});
}
Aggregations