Search in sources :

Example 1 with Module

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;
}
Also used : LinkTransformationMethod(de.robv.android.xposed.installer.util.chrome.LinkTransformationMethod) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) Module(de.robv.android.xposed.installer.repo.Module) TextView(android.widget.TextView) View(android.view.View) Uri(android.net.Uri)

Example 2 with Module

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();
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SyncDownloadInfo(de.robv.android.xposed.installer.util.DownloadsUtil.SyncDownloadInfo) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Repository(de.robv.android.xposed.installer.repo.Repository) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Module(de.robv.android.xposed.installer.repo.Module) File(java.io.File) RepoParserCallback(de.robv.android.xposed.installer.repo.RepoParser.RepoParserCallback)

Example 3 with Module

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;
}
Also used : Context(android.content.Context) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) RepoLoader(de.robv.android.xposed.installer.util.RepoLoader) ActivityNotFoundException(android.content.ActivityNotFoundException) ModuleVersion(de.robv.android.xposed.installer.repo.ModuleVersion) BufferedReader(java.io.BufferedReader) InstalledModule(de.robv.android.xposed.installer.util.ModuleUtil.InstalledModule) Module(de.robv.android.xposed.installer.repo.Module) DownloadsUtil(de.robv.android.xposed.installer.util.DownloadsUtil)

Example 4 with Module

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;
        }
    });
}
Also used : PrefixedSharedPreferences(de.robv.android.xposed.installer.util.PrefixedSharedPreferences) SharedPreferences(android.content.SharedPreferences) Preference(android.preference.Preference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) Module(de.robv.android.xposed.installer.repo.Module) PreferenceManager(android.preference.PreferenceManager) Map(java.util.Map)

Aggregations

Module (de.robv.android.xposed.installer.repo.Module)4 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 Uri (android.net.Uri)1 Preference (android.preference.Preference)1 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)1 PreferenceManager (android.preference.PreferenceManager)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 ModuleVersion (de.robv.android.xposed.installer.repo.ModuleVersion)1 RepoParserCallback (de.robv.android.xposed.installer.repo.RepoParser.RepoParserCallback)1 Repository (de.robv.android.xposed.installer.repo.Repository)1 DownloadsUtil (de.robv.android.xposed.installer.util.DownloadsUtil)1 SyncDownloadInfo (de.robv.android.xposed.installer.util.DownloadsUtil.SyncDownloadInfo)1 InstalledModule (de.robv.android.xposed.installer.util.ModuleUtil.InstalledModule)1