Looking good...

This commit is contained in:
d8ahazard 2016-09-09 16:49:25 -05:00
parent 214649ec20
commit 1a1d37a2d0
10 changed files with 464 additions and 152 deletions

View File

@ -1,5 +1,8 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.animation.Animator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -7,18 +10,23 @@ import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.topjohnwu.magisk.module.Module; import com.topjohnwu.magisk.module.Module;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import butterknife.BindView; import butterknife.BindView;
@ -35,17 +43,17 @@ public abstract class BaseModuleFragment extends Fragment {
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.single_module_fragment, container, false); View viewMain = inflater.inflate(R.layout.single_module_fragment, container, false);
ButterKnife.bind(this, view); ButterKnife.bind(this, viewMain);
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
prefs.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() { prefs.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
if (s.contains("updated")) { if (s.contains("updated")) {
view.invalidate(); viewMain.invalidate();
view.requestLayout(); viewMain.requestLayout();
} }
} }
@ -54,7 +62,7 @@ public abstract class BaseModuleFragment extends Fragment {
emptyTv.setVisibility(View.VISIBLE); emptyTv.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE); recyclerView.setVisibility(View.GONE);
return view; return viewMain;
} }
recyclerView.setAdapter(new ModulesAdapter(listModules(), (chk, position) -> { recyclerView.setAdapter(new ModulesAdapter(listModules(), (chk, position) -> {
@ -79,7 +87,7 @@ public abstract class BaseModuleFragment extends Fragment {
listModules().get(position).deleteRemoveFile(); listModules().get(position).deleteRemoveFile();
Snackbar.make(undeleteBtn, R.string.remove_file_deleted, Snackbar.LENGTH_SHORT).show(); Snackbar.make(undeleteBtn, R.string.remove_file_deleted, Snackbar.LENGTH_SHORT).show();
})); }));
return view; return viewMain;
} }
@ -88,12 +96,21 @@ public abstract class BaseModuleFragment extends Fragment {
public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHolder> { public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHolder> {
private final List<Module> mList; private final List<Module> mList;
List<Boolean> mExpandedList;
@BindView(R.id.expand_layout)
LinearLayout expandedLayout;
private View viewMain;
private Context context;
private final Utils.ItemClickListener chboxListener; private final Utils.ItemClickListener chboxListener;
private final Utils.ItemClickListener deleteBtnListener; private final Utils.ItemClickListener deleteBtnListener;
private final Utils.ItemClickListener unDeleteBtnListener; private final Utils.ItemClickListener unDeleteBtnListener;
public ModulesAdapter(List<Module> list, Utils.ItemClickListener chboxListener, Utils.ItemClickListener deleteBtnListener, Utils.ItemClickListener undeleteBtnListener) { public ModulesAdapter(List<Module> list, Utils.ItemClickListener chboxListener, Utils.ItemClickListener deleteBtnListener, Utils.ItemClickListener undeleteBtnListener) {
this.mList = list; this.mList = list;
mExpandedList = new ArrayList<>(mList.size());
for (int i = 0; i < mList.size(); i++) {
mExpandedList.add(false);
}
this.chboxListener = chboxListener; this.chboxListener = chboxListener;
this.deleteBtnListener = deleteBtnListener; this.deleteBtnListener = deleteBtnListener;
this.unDeleteBtnListener = undeleteBtnListener; this.unDeleteBtnListener = undeleteBtnListener;
@ -101,9 +118,10 @@ public abstract class BaseModuleFragment extends Fragment {
@Override @Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_module, parent, false); viewMain = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_module, parent, false);
context = parent.getContext();
return new ViewHolder(view); ButterKnife.bind(this, viewMain);
return new ViewHolder(viewMain);
} }
@Override @Override
@ -158,15 +176,103 @@ public abstract class BaseModuleFragment extends Fragment {
@BindView(R.id.checkbox) CheckBox checkBox; @BindView(R.id.checkbox) CheckBox checkBox;
@BindView(R.id.delete) @BindView(R.id.delete)
ImageView delete; ImageView delete;
@BindView(R.id.expand_layout)
LinearLayout expandLayout;
private ValueAnimator mAnimator;
private int mMeasuredHeight;
public ViewHolder(View itemView) { public ViewHolder(View itemView) {
super(itemView); super(itemView);
WindowManager windowmanager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
ButterKnife.bind(this, itemView); ButterKnife.bind(this, itemView);
DisplayMetrics dimension = new DisplayMetrics();
windowmanager.getDefaultDisplay().getMetrics(dimension);
final int mHeight = dimension.heightPixels;
expandLayout.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
expandLayout.getViewTreeObserver().removeOnPreDrawListener(this);
expandLayout.setVisibility(View.GONE);
final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightSpec = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
expandLayout.measure(widthSpec, heightSpec);
mAnimator = slideAnimator(0, expandLayout.getMeasuredHeight());
return true;
}
});
viewMain.setOnClickListener(view -> {
int position = getAdapterPosition();
Log.d("Magisk", "BaseRepoFragment: CLICK. " + position + " and " + mExpandedList.get(position));
if (mExpandedList.get(position)) {
collapse(expandLayout);
} else {
expand(expandLayout);
}
mExpandedList.set(position, !mExpandedList.get(position));
});
if (!Shell.rootAccess()) { if (!Shell.rootAccess()) {
checkBox.setEnabled(false); checkBox.setEnabled(false);
delete.setEnabled(false); delete.setEnabled(false);
} }
} }
private void expand(View view) {
// set Visible
Log.d("Magisk", "BaseRepoFragment: Expand anim called " + mMeasuredHeight + " and " + view.getId());
view.setVisibility(View.VISIBLE);
mAnimator.start();
}
private void collapse(View view) {
int finalHeight = view.getHeight();
ValueAnimator mAnimator = slideAnimator(finalHeight, 0);
Log.d("Magisk", "BaseRepoFragment: Collapse anim called " + finalHeight + " and " + view.getId());
mAnimator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationEnd(Animator animator) {
// Height=0, but it set visibility to GONE
view.setVisibility(View.GONE);
}
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
mAnimator.start();
}
private ValueAnimator slideAnimator(int start, int end) {
ValueAnimator animator = ValueAnimator.ofInt(start, end);
animator.addUpdateListener(valueAnimator -> {
// Update Height
int value = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = expandLayout
.getLayoutParams();
layoutParams.height = value;
expandLayout.setLayoutParams(layoutParams);
});
return animator;
}
} }
} }
} }

View File

@ -1,26 +1,33 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.animation.Animator;
import android.animation.ValueAnimator;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.util.Linkify;
import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.topjohnwu.magisk.module.Repo; import com.topjohnwu.magisk.module.Repo;
import com.topjohnwu.magisk.utils.AnimationHelper;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import butterknife.BindView; import butterknife.BindView;
@ -33,15 +40,11 @@ public abstract class BaseRepoFragment extends Fragment {
@BindView(R.id.empty_rv) @BindView(R.id.empty_rv)
TextView emptyTv; TextView emptyTv;
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.single_module_fragment, container, false); View view = inflater.inflate(R.layout.single_module_fragment, container, false);
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
if (listRepos().size() == 0) { if (listRepos().size() == 0) {
@ -50,7 +53,7 @@ public abstract class BaseRepoFragment extends Fragment {
return view; return view;
} }
Log.d("Magisk","BaseRepoFragment: ListRepos size is " + listRepos().size()); Log.d("Magisk", "BaseRepoFragment: ListRepos size is " + listRepos().size());
recyclerView.setAdapter(new ReposAdapter(listRepos()) { recyclerView.setAdapter(new ReposAdapter(listRepos()) {
}); });
@ -63,21 +66,23 @@ public abstract class BaseRepoFragment extends Fragment {
public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder> { public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder> {
private final List<Repo> mList; private final List<Repo> mList;
private View viewMain; List<Boolean> mExpandedList;
private Context context;
@BindView(R.id.update) @BindView(R.id.update)
ImageView updateImage; ImageView updateImage;
@BindView(R.id.installed) @BindView(R.id.installed)
ImageView installedImage; ImageView installedImage;
// @BindView(R.id.popup_layout) @BindView(R.id.expand_layout)
// LinearLayout popupLayout; LinearLayout expandedLayout;
private View viewMain;
private Context context;
private boolean isCardExpanded;
private boolean mIsInstalled, mCanUpdate; private boolean mIsInstalled, mCanUpdate;
public ReposAdapter(List<Repo> list) { public ReposAdapter(List<Repo> list) {
this.mList = list; this.mList = list;
mExpandedList = new ArrayList<>(mList.size());
for (int i = 0; i < mList.size(); i++) {
mExpandedList.add(false);
}
} }
@ -92,64 +97,69 @@ public abstract class BaseRepoFragment extends Fragment {
@Override @Override
public void onBindViewHolder(final ViewHolder holder, int position) { public void onBindViewHolder(final ViewHolder holder, int position) {
final Repo repo = mList.get(position); final Repo repo = mList.get(position);
Log.d("Magisk","ReposAdapter: Trying set up bindview from list pos " + position + " out of a total of " + mList.size() + " and " + repo.getId() );
Log.d("Magisk", "ReposAdapter: Trying set up bindview from list pos " + position + " out of a total of " + mList.size() + " and " + repo.getId());
if (repo.getId() != null) { if (repo.getId() != null) {
TextView authorView = holder.author;
holder.title.setText(repo.getName()); holder.title.setText(repo.getName());
holder.versionName.setText(repo.getmVersion()); holder.versionName.setText(repo.getmVersion());
holder.description.setText(repo.getDescription()); holder.description.setText(repo.getDescription());
String authorString = getResources().getString(R.string.author) + " " + repo.getmAuthor();
holder.author.setText(authorString);
if ((repo.getmLogUrl() != null) && (repo.getmLogUrl().equals(""))) {
holder.log.setText(repo.getmLogUrl());
Linkify.addLinks(holder.log, Linkify.WEB_URLS);
} else {
holder.log.setVisibility(View.GONE);
}
holder.installedStatus.setText(repo.isInstalled() ? getResources().getString(R.string.module_installed) : getResources().getString(R.string.module_not_installed));
if (mExpandedList.get(position)) {
holder.expandLayout.setVisibility(View.VISIBLE);
} else {
holder.expandLayout.setVisibility(View.GONE);
}
if (repo.isInstalled()) {
holder.installedStatus.setTextColor(Color.parseColor("#14AD00"));
holder.updateStatus.setText(repo.canUpdate() ? getResources().getString(R.string.module_update_available) : getResources().getString(R.string.module_up_to_date));
}
Log.d("Magisk", "ReposAdapter: Setting up info " + repo.getId() + " and " + repo.getDescription() + " and " + repo.getmVersion()); Log.d("Magisk", "ReposAdapter: Setting up info " + repo.getId() + " and " + repo.getDescription() + " and " + repo.getmVersion());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (prefs.contains("repo-isInstalled_" + repo.getId())) { updateImage.setImageResource(R.drawable.ic_system_update_alt_black);
mIsInstalled = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false); mCanUpdate = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false);
if (mIsInstalled) { updateImage.setOnClickListener(new View.OnClickListener() {
installedImage.setImageResource(R.drawable.ic_done_black);
}
mCanUpdate = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false);
if (mCanUpdate) {
updateImage.setImageResource(R.drawable.ic_system_update_alt_black);
}
}
isCardExpanded = false;
// AnimationHelper.collapse(popupLayout);
viewMain.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (isCardExpanded) { if (!mIsInstalled | mCanUpdate) {
// AnimationHelper.expand(popupLayout);
isCardExpanded = false; Utils.DownloadReceiver reciever = new Utils.DownloadReceiver() {
@Override
public void task(File file) {
Log.d("Magisk", "Task firing");
new Utils.FlashZIP(context, repo.getId(), file.toString()).execute();
}
};
String filename = repo.getId().replace(" ", "") + ".zip";
Utils.downloadAndReceive(context, reciever, repo.getmZipUrl(), filename);
} else { } else {
// AnimationHelper.collapse(popupLayout); Toast.makeText(context, repo.getId() + " is already installed.", Toast.LENGTH_SHORT).show();
isCardExpanded = true;
} }
// if (!mIsInstalled | mCanUpdate) {
//
// Utils.DownloadReceiver reciever = new Utils.DownloadReceiver() {
// @Override
// public void task(File file) {
// Log.d("Magisk", "Task firing");
// new Utils.FlashZIP(context, repo.getId(), file.toString()).execute();
// }
// };
// String filename = repo.getId().replace(" ", "") + ".zip";
// Utils.downloadAndReceive(context, reciever, repo.getmZipUrl(), filename);
// } else {
// Toast.makeText(context,repo.getId() + " is already installed.", Toast.LENGTH_SHORT).show();
// }
} }
}); });
if (prefs.contains("repo-isInstalled_" + repo.getId())) {
mIsInstalled = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false);
// if (mIsInstalled) {
// installedImage.setImageResource(R.drawable.ic_done_black);
// }
}
} }
} }
@Override @Override
public int getItemCount() { public int getItemCount() {
return mList.size(); return mList.size();
@ -157,15 +167,120 @@ public abstract class BaseRepoFragment extends Fragment {
class ViewHolder extends RecyclerView.ViewHolder { class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.title) TextView title; @BindView(R.id.title)
@BindView(R.id.version_name) TextView versionName; TextView title;
@BindView(R.id.description) TextView description; @BindView(R.id.version_name)
TextView versionName;
@BindView(R.id.description)
TextView description;
@BindView(R.id.author)
TextView author;
@BindView(R.id.log)
TextView log;
@BindView(R.id.installedStatus)
TextView installedStatus;
@BindView(R.id.updateStatus)
TextView updateStatus;
@BindView(R.id.expand_layout)
LinearLayout expandLayout;
private ValueAnimator mAnimator;
private int mMeasuredHeight;
public ViewHolder(View itemView) { public ViewHolder(View itemView) {
super(itemView); super(itemView);
WindowManager windowmanager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
ButterKnife.bind(this, itemView); ButterKnife.bind(this, itemView);
DisplayMetrics dimension = new DisplayMetrics();
windowmanager.getDefaultDisplay().getMetrics(dimension);
final int mHeight = dimension.heightPixels;
expandLayout.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
expandLayout.getViewTreeObserver().removeOnPreDrawListener(this);
expandLayout.setVisibility(View.GONE);
final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
expandLayout.measure(widthSpec, heightSpec);
mAnimator = slideAnimator(0, expandLayout.getMeasuredHeight());
return true;
}
});
viewMain.setOnClickListener(view -> {
int position = getAdapterPosition();
Log.d("Magisk", "BaseRepoFragment: CLICK. " + position + " and " + mExpandedList.get(position));
if (mExpandedList.get(position)) {
collapse(expandLayout);
} else {
expand(expandLayout);
}
mExpandedList.set(position, !mExpandedList.get(position));
});
} }
private void expand(View view) {
// set Visible
Log.d("Magisk", "BaseRepoFragment: Expand anim called " + mMeasuredHeight + " and " + view.getId());
view.setVisibility(View.VISIBLE);
mAnimator.start();
}
private void collapse(View view) {
int finalHeight = view.getHeight();
ValueAnimator mAnimator = slideAnimator(finalHeight, 0);
Log.d("Magisk", "BaseRepoFragment: Collapse anim called " + finalHeight + " and " + view.getId());
mAnimator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationEnd(Animator animator) {
// Height=0, but it set visibility to GONE
view.setVisibility(View.GONE);
}
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
mAnimator.start();
}
private ValueAnimator slideAnimator(int start, int end) {
ValueAnimator animator = ValueAnimator.ofInt(start, end);
animator.addUpdateListener(valueAnimator -> {
// Update Height
int value = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = expandLayout
.getLayoutParams();
layoutParams.height = value;
expandLayout.setLayoutParams(layoutParams);
});
return animator;
}
} }
} }
} }

View File

@ -41,9 +41,7 @@ public class ModulesFragment extends Fragment {
public static List<Module> listModulesCache = new ArrayList<>(); public static List<Module> listModulesCache = new ArrayList<>();
public static List<Repo> listModulesDownload = new ArrayList<>(); public static List<Repo> listModulesDownload = new ArrayList<>();
private static final int FILE_SELECT_CODE = 0; private static final int FILE_SELECT_CODE = 0;
private TabsAdapter ta; private int viewPagePosition;
private File input;
private SwipeRefreshLayout mSwipeRefreshLayout;
@BindView(R.id.progressBar) ProgressBar progressBar; @BindView(R.id.progressBar) ProgressBar progressBar;
@BindView(R.id.fab) FloatingActionButton fabio; @BindView(R.id.fab) FloatingActionButton fabio;
@ -56,7 +54,7 @@ public class ModulesFragment extends Fragment {
View view = inflater.inflate(R.layout.modules_fragment, container, false); View view = inflater.inflate(R.layout.modules_fragment, container, false);
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
//new Utils.LoadModules(getActivity(),false).execute(); new Utils.LoadModules(getActivity(),false).execute();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
new updateUI().execute(); new updateUI().execute();
setHasOptionsMenu(true); setHasOptionsMenu(true);
@ -101,12 +99,14 @@ public class ModulesFragment extends Fragment {
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.force_reload: case R.id.force_reload:
viewPagePosition = tabLayout.getSelectedTabPosition();
listModules.clear(); listModules.clear();
listModulesCache.clear(); listModulesCache.clear();
listModulesDownload.clear(); listModulesDownload.clear();
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager())); viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
tabLayout.setupWithViewPager(viewPager); tabLayout.setupWithViewPager(viewPager);
viewPager.setCurrentItem(viewPagePosition);
new Utils.LoadModules(getActivity(),true).execute(); new Utils.LoadModules(getActivity(),true).execute();
new updateUI().execute(); new updateUI().execute();
break; break;
@ -115,6 +115,11 @@ public class ModulesFragment extends Fragment {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
void selectPage(int pageIndex){
tabLayout.setScrollPosition(pageIndex,0f,true);
viewPager.setCurrentItem(pageIndex);
}
public static class NormalModuleFragment extends BaseModuleFragment { public static class NormalModuleFragment extends BaseModuleFragment {
@Override @Override
@ -154,9 +159,10 @@ public class ModulesFragment extends Fragment {
super.onPostExecute(v); super.onPostExecute(v);
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager())); viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
tabLayout.setupWithViewPager(viewPager); tabLayout.setupWithViewPager(viewPager);
selectPage(viewPagePosition);
} }
} }
@ -186,7 +192,7 @@ public class ModulesFragment extends Fragment {
return new NormalModuleFragment(); return new NormalModuleFragment();
} else if (position == 1) { } else if (position == 1) {
return new CacheModuleFragment(); return new CacheModuleFragment();
} else { } else {
return new DownloadModuleFragment(); return new DownloadModuleFragment();
} }
} }

View File

@ -29,7 +29,7 @@ public class RepoHelper {
private static final String TAG_ID = "id"; private static final String TAG_ID = "id";
private static final String TAG_NAME = "name"; private static final String TAG_NAME = "name";
private static String TAG = "Magisk"; private static String TAG = "Magisk";
private String mName,mId,mUrl; private String mName, mId, mUrl;
private Context activityContext; private Context activityContext;
private Date updatedDate, currentDate; private Date updatedDate, currentDate;
private SharedPreferences prefs; private SharedPreferences prefs;
@ -44,35 +44,7 @@ public class RepoHelper {
List<String> out = null; List<String> out = null;
} else { } else {
Log.d(TAG, "RepoHelper: Building from cache"); Log.d(TAG, "RepoHelper: Building from cache");
repos.clear(); BuildFromCache();
Map<String, ?> map = prefs.getAll();
for(Map.Entry<String,?> entry : map.entrySet()){
if (entry.getKey().contains("repo_")) {
Log.d("Magisk","RepoHelper: found entry for repo " + entry.getKey());
String repoString = entry.getValue().toString().replace("&quot;", "\"");
String[] repoStrings = repoString.split("\n");
for(String string : repoStrings) {
String[] splitStrings = string.split("=");
switch(splitStrings[0]) {
case ("id"):
mId = splitStrings[1];
break;
case ("baseUrl"):
mUrl = splitStrings[1];
break;
default:
break;
}
}
Log.d("Magisk","RepoHelper: adding repo with id of " + mId);
repos.add(new Repo(repoString,activityContext));
}
}
} }
@ -81,6 +53,37 @@ public class RepoHelper {
return repos; return repos;
} }
private void BuildFromCache() {
repos.clear();
Map<String, ?> map = prefs.getAll();
for (Map.Entry<String, ?> entry : map.entrySet()) {
if (entry.getKey().contains("repo_")) {
Log.d("Magisk", "RepoHelper: found entry for repo " + entry.getKey());
String repoString = entry.getValue().toString().replace("&quot;", "\"");
String[] repoStrings = repoString.split("\n");
for (String string : repoStrings) {
String[] splitStrings = string.split("=");
switch (splitStrings[0]) {
case ("id"):
mId = splitStrings[1];
break;
case ("baseUrl"):
mUrl = splitStrings[1];
break;
default:
break;
}
}
Log.d("Magisk", "RepoHelper: adding repo with id of " + mId);
repos.add(new Repo(repoString, activityContext));
}
}
}
class MyAsyncTask extends AsyncTask<String, String, Void> { class MyAsyncTask extends AsyncTask<String, String, Void> {
@ -105,9 +108,9 @@ public class RepoHelper {
// Making a request to url and getting response // Making a request to url and getting response
String token = activityContext.getString(R.string.some_string); String token = activityContext.getString(R.string.some_string);
String jsonStr = webreq.makeWebServiceCall(url + Utils.procFile(token,activityContext), WebRequest.GET); String jsonStr = webreq.makeWebServiceCall(url + Utils.procFile(token, activityContext), WebRequest.GET);
Log.d("Magisk", "doInBackground Running, String: " + jsonStr + " Url: " + url); Log.d("Magisk", "doInBackground Running, String: " + jsonStr + " Url: " + url);
if(jsonStr != null && !jsonStr.isEmpty()) { if (jsonStr != null && !jsonStr.isEmpty()) {
try { try {
repos.clear(); repos.clear();
@ -185,7 +188,9 @@ public class RepoHelper {
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
if (apiFail) { if (apiFail) {
Toast.makeText(activityContext,"GitHub API Limit reached, please try refreshing again in an hour.",Toast.LENGTH_LONG).show(); Toast.makeText(activityContext, "GitHub API Limit reached, please try refreshing again in an hour.", Toast.LENGTH_LONG).show();
} else {
BuildFromCache();
} }
} // protected void onPostExecute(Void v) } // protected void onPostExecute(Void v)

View File

@ -4,6 +4,6 @@
android:viewportWidth="24.0" android:viewportWidth="24.0"
android:viewportHeight="24.0"> android:viewportHeight="24.0">
<path <path
android:fillColor="#FF000000" android:fillColor="#757575"
android:pathData="M12,16.5l4,-4h-3v-9h-2v9L8,12.5l4,4zM21,3.5h-6v1.99h6v14.03L3,19.52L3,5.49h6L9,3.5L3,3.5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2v-14c0,-1.1 -0.9,-2 -2,-2z"/> android:pathData="M12,16.5l4,-4h-3v-9h-2v9L8,12.5l4,4zM21,3.5h-6v1.99h6v14.03L3,19.52L3,5.49h6L9,3.5L3,3.5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2v-14c0,-1.1 -0.9,-2 -2,-2z"/>
</vector> </vector>

View File

@ -13,6 +13,10 @@
android:minHeight="?android:attr/listPreferredItemHeight" android:minHeight="?android:attr/listPreferredItemHeight"
card_view:cardCornerRadius="2dp" card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp"> card_view:cardElevation="2dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -64,9 +68,24 @@
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/red500" android:textColor="@color/red500"
android:visibility="gone"/> android:visibility="gone"/>
<LinearLayout
android:id="@+id/expand_layout"
android:minHeight="100dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/tertiary_text_dark"
android:textIsSelectable="false"
android:textStyle="bold|italic" />
</LinearLayout> </LinearLayout>
</LinearLayout>
<CheckBox <CheckBox
android:id="@+id/checkbox" android:id="@+id/checkbox"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -86,6 +105,9 @@
android:padding="3dp" android:padding="3dp"
android:src="@drawable/ic_delete" android:src="@drawable/ic_delete"
tools:ignore="ContentDescription"/> tools:ignore="ContentDescription"/>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -60,22 +60,64 @@
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="false"/> android:textIsSelectable="false"/>
<LinearLayout
android:id="@+id/expand_layout"
android:minHeight="100dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/tertiary_text_dark"
android:textIsSelectable="false"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/log"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="false"/>
<TextView
android:id="@+id/installedStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="false"/>
<TextView
android:id="@+id/updateStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="false"/>
</LinearLayout>
</LinearLayout> </LinearLayout>
<ImageView <ImageView
android:id="@+id/installed" android:id="@+id/installed"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="match_parent"
android:focusable="false"
android:gravity="center"
android:padding="5dp"
/>
<ImageView <ImageView
android:id="@+id/update" android:id="@+id/update"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="match_parent"
android:focusable="false"
android:gravity="center"
android:padding="5dp" />
</LinearLayout> </LinearLayout>
<!-- <include layout="@layout/list_item_repo_expanded" />-->
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>

View File

@ -1,54 +1,67 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/llayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<android.support.design.widget.TabLayout <RelativeLayout
android:id="@+id/tab_layout" android:layout_width="fill_parent"
android:layout_width="match_parent" android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
app:tabGravity="fill"
app:tabIndicatorColor="?attr/colorAccent"
app:tabMode="fixed"
app:tabTextAppearance="@style/TextAppearance.Design.Tab"/>
<ProgressBar <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/progressBar" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content" android:id="@+id/llayout"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:layout_gravity="center"/> android:layout_height="fill_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<android.support.v4.view.ViewPager <android.support.design.widget.TabLayout
android:id="@+id/pager" android:id="@+id/tab_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
app:tabGravity="fill"
app:tabIndicatorColor="?attr/colorAccent"
app:tabMode="fixed"
app:tabTextAppearance="@style/TextAppearance.Design.Tab" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true" />
</LinearLayout> </LinearLayout>
<android.support.design.widget.FloatingActionButton <LinearLayout
android:id="@+id/fab" android:id="@+id/ly_bar_bottom"
android:layout_width="wrap_content" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="right" android:layout_alignParentBottom="true"
android:layout_margin="16dp" android:gravity="center"
android:clickable="true" android:orientation="horizontal">
app:layout_anchor="@id/llayout" <android.support.design.widget.FloatingActionButton
android:src="@drawable/ic_add" android:id="@+id/fab"
app:layout_anchorGravity="bottom|right|end" android:layout_width="wrap_content"
/> android:layout_height="wrap_content"
android:layout_margin="16dp"
android:baselineAlignBottom="false"
android:clickable="true"
android:src="@drawable/ic_add"
app:layout_anchorGravity="bottom|right|end"
/>
</LinearLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>

View File

@ -2,4 +2,5 @@
<resources> <resources>
<dimen name="floating_height">650dp</dimen> <dimen name="floating_height">650dp</dimen>
<dimen name="floating_width">500dp</dimen> <dimen name="floating_width">500dp</dimen>
<dimen name="min_rowheight">100dp</dimen>
</resources> </resources>

View File

@ -42,13 +42,15 @@
<!--Module Fragment--> <!--Module Fragment-->
<string name="cache_modules">Cache modules</string> <string name="cache_modules">Cache modules</string>
<string name="no_modules_found">No modules found</string> <string name="no_modules_found">No modules found</string>
<string name="module_update_available">Update available</string> <string name="module_update_available">An update is available</string>
<string name="mudule_up_to_date">Module is up-to-date</string> <string name="module_up_to_date">Module is up-to-date</string>
<string name="module_installed">Module is installed</string> <string name="module_installed">Module is installed</string>
<string name="module_not_installed">Module is not installed</string>
<string name="remove_file_created">Module will be removed at next reboot</string> <string name="remove_file_created">Module will be removed at next reboot</string>
<string name="remove_file_deleted">Module will not be removed at next reboot</string> <string name="remove_file_deleted">Module will not be removed at next reboot</string>
<string name="disable_file_created">Module will be disabled at next reboot</string> <string name="disable_file_created">Module will be disabled at next reboot</string>
<string name="disable_file_removed">Module will be enabled at next reboot</string> <string name="disable_file_removed">Module will be enabled at next reboot</string>
<string name="author">Created by </string>
<!--Log Fragment--> <!--Log Fragment-->
<string name="menuSaveToSd">Save to SD</string> <string name="menuSaveToSd">Save to SD</string>