[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge pull request #41 from rumboalla/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rumboalla committed Mar 17, 2017
2 parents 2645132 + 3cd3676 commit ce59170
Show file tree
Hide file tree
Showing 13 changed files with 302 additions and 101 deletions.
14 changes: 11 additions & 3 deletions app/src/main/java/com/apkupdater/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
Expand Down Expand Up @@ -70,7 +69,16 @@ public void onCreate(
setSupportActionBar(mToolbar);

mBus.register(this);
mAppState.clearUpdates();

// Clear updates unless we are coming from a notification
boolean isFromNotification = false;
try {
isFromNotification = getIntent().getExtras().getBoolean("isFromNotification");
} catch (Exception ignored) {}

if (!isFromNotification) {
mAppState.clearUpdates();
}

// Simulate a boot com.apkupdater.receiver to set alarm
new BootReceiver_().onReceive(getBaseContext(), null);
Expand All @@ -83,7 +91,7 @@ public void onCreate(
// Add the main fragment
if (!(getSupportFragmentManager().findFragmentById(R.id.container) instanceof MainFragment)) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, mMainFragment)
.replace(R.id.container, mMainFragment)
.add(R.id.container, mSettingsFragment)
.add(R.id.container, mLogFragment)
.show(mMainFragment)
Expand Down
33 changes: 26 additions & 7 deletions app/src/main/java/com/apkupdater/adapter/InstalledAppAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public class InstalledAppAdapter
extends RecyclerView.Adapter<InstalledAppAdapter.InstalledAppViewHolder>
implements View.OnLongClickListener
implements View.OnClickListener
{
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -77,26 +77,47 @@ public InstalledAppViewHolder onCreateViewHolder(
ViewGroup parent,
int viewType
) {
InstalledAppView v = InstalledAppView_.build(mContext);
InstalledAppView v = InstalledAppView_.build(parent.getContext());
v.setLayoutParams(new RecyclerView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
));
v.setOnLongClickListener(this);
v.setActionOneButtonListener(this);
//v.setOnLongClickListener(this);
return new InstalledAppViewHolder(v);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

private InstalledAppView getInstalledAppViewParent(
View v
) {
while (v != null) {
v = (View) v.getParent();
if (v instanceof InstalledAppView) {
return (InstalledAppView) v;
}
}
return null;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

@Override
public boolean onLongClick(
public void onClick(
View view
) {
// Get the ignore list from the options
UpdaterOptions options = new UpdaterOptions(mContext);
List<String> ignore_list = options.getIgnoreList();

InstalledApp app = mApps.get(mView.getChildLayoutPosition(view));
// Get the InstalledAppView parent
InstalledAppView parent = getInstalledAppViewParent(view);
if (parent == null) {
return;
}

InstalledApp app = mApps.get(mView.getChildLayoutPosition(parent));

// If it's on the ignore remove, otherwise add it
if (ignore_list.contains(app.getPname())) {
Expand All @@ -112,8 +133,6 @@ public boolean onLongClick(
AnimationUtil.startListAnimation(mView);
mApps = InstalledAppUtil.sort(mContext, mApps);
notifyDataSetChanged();

return true;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
55 changes: 34 additions & 21 deletions app/src/main/java/com/apkupdater/adapter/UpdaterAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

public class UpdaterAdapter
extends RecyclerView.Adapter<UpdaterAdapter.UpdateViewHolder>
implements View.OnLongClickListener, View.OnClickListener
{
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -80,40 +79,54 @@ public UpdateViewHolder onCreateViewHolder(
ViewGroup parent,
int viewType
) {
UpdaterView v = UpdaterView_.build(mContext);
UpdaterView v = UpdaterView_.build(parent.getContext());
v.setLayoutParams(new RecyclerView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
));
v.setOnLongClickListener(this);
v.setOnClickListener(this);

v.setActionOneButtonListener(onActionOneClick);
v.setActionTwoButtonListener(onActionTwoClick);
return new UpdateViewHolder(v);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

@Override
public boolean onLongClick(
View view
private UpdaterView getUpdaterViewParent(
View v
) {
Update update = mUpdates.get(mView.getChildLayoutPosition(view));
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
"https://apps.evozi.com/apk-downloader/?id=" + update.getPname()
));
mContext.startActivity(browserIntent);
return true;
while (v != null) {
v = (View) v.getParent();
if (v instanceof UpdaterView) {
return (UpdaterView) v;
}
}
return null;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

@Override
public void onClick(
View view
) {
Update update = mUpdates.get(mView.getChildLayoutPosition(view));
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(update.getUrl()));
mContext.startActivity(browserIntent);
}
private View.OnClickListener onActionTwoClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
Update update = mUpdates.get(mView.getChildLayoutPosition(getUpdaterViewParent(v)));
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
"https://apps.evozi.com/apk-downloader/?id=" + update.getPname()
));
mContext.startActivity(browserIntent);
}
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

private View.OnClickListener onActionOneClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
Update update = mUpdates.get(mView.getChildLayoutPosition(getUpdaterViewParent(v)));
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(update.getUrl()));
mContext.startActivity(browserIntent);
}
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down
12 changes: 5 additions & 7 deletions app/src/main/java/com/apkupdater/fragment/UpdaterFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,11 @@ private void loadData(
mProgressCount = mAppState.getUpdateProgress();
mProgressMax = mAppState.getUpdateMax();

if (mProgressCount == 0 && mProgressMax == 0) {
// Get the updates and add them to the adapter
List<Update> updates = mAppState.getUpdates();
if (!updates.isEmpty()) {
mAdapter.setUpdates(updates);
sendUpdateTitleEvent();
}
// Get the updates and add them to the adapter
List<Update> updates = mAppState.getUpdates();
if (!updates.isEmpty()) {
mAdapter.setUpdates(updates);
sendUpdateTitleEvent();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public void onReceive(
) {
mAppState.setFirstStart(false);
mAppState.setSelectedTab(1);
MainActivity_.intent(context).flags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP).start();
MainActivity_.intent(context)
.extra("isFromNotification", true)
.flags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP)
.start();
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ public void checkForUpdates(
mNotification.setMaxApps(appCount);

// Send start event
mLogger.log("test", "test", LogMessage.SEVERITY_ERROR);
mBus.post(new UpdateStartEvent(appCount));

// Wait until all threads are done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void updateNotification(
private PendingIntent createPendingIntent(
) {
Intent intent = new Intent("com.apkupdater.notification");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.setFlags(0);
return PendingIntent.getBroadcast(mContext, 0, intent, 0);
}

Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/com/apkupdater/view/InstalledAppView.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
Expand Down Expand Up @@ -36,6 +38,9 @@ public class InstalledAppView
@ViewById(R.id.installed_app_icon)
ImageView mIcon;

@ViewById(R.id.action_one_button)
Button mActionOneButton;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public InstalledAppView(
Expand All @@ -61,12 +66,14 @@ public void bind(
} else {
setBackgroundColor(0x55000000);
}
mActionOneButton.setText(R.string.action_unignore_app);
} else {
if (android.os.Build.VERSION.SDK_INT >= 11) { // No alpha for old versions
setAlpha(1.0f);
} else {
setBackgroundColor(0x00FFFFFF);
}
mActionOneButton.setText(R.string.action_ignore_app);
}

try {
Expand All @@ -78,6 +85,14 @@ public void bind(
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public void setActionOneButtonListener(
View.OnClickListener listener
) {
mActionOneButton.setOnClickListener(listener);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
44 changes: 39 additions & 5 deletions app/src/main/java/com/apkupdater/view/UpdaterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.apkupdater.R;
import com.apkupdater.model.Update;
import com.apkupdater.util.ColorUtitl;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;
Expand Down Expand Up @@ -39,12 +40,21 @@ public class UpdaterView
@ViewById(R.id.update_url)
TextView mUrl;

@ViewById(R.id.action_one_button)
Button mActionOneButton;

@ViewById(R.id.action_two_button)
Button mActionTwoButton;

Context mContext;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public UpdaterView(
Context context
) {
super(context);
mContext = context;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -62,14 +72,38 @@ public void bind(
}

mVersion.setText(version);
mUrl.setText(update.getUrl());
mUrl.setTextColor(ColorUtitl.getColorFromTheme(getContext().getTheme(), R.attr.colorAccent));

// Build string for first action
String action = "";
if (update.getUrl().contains("apkmirror.com")) {
action = mContext.getString(R.string.action_apkmirror);
} else if (update.getUrl().contains("uptodown.com")) {
action = mContext.getString(R.string.action_uptodown);
} else if (update.getUrl().contains("apkpure.com")) {
action = mContext.getString(R.string.action_apkpure);
}
mActionOneButton.setText(action);

try {
Drawable icon = getContext().getPackageManager().getApplicationIcon(update.getPname());
mIcon.setImageDrawable(icon);
} catch (PackageManager.NameNotFoundException ignored) {
} catch (PackageManager.NameNotFoundException ignored) {}
}

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public void setActionOneButtonListener(
View.OnClickListener listener
) {
mActionOneButton.setOnClickListener(listener);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public void setActionTwoButtonListener(
View.OnClickListener listener
) {
mActionTwoButton.setOnClickListener(listener);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit ce59170

Please sign in to comment.