Skip to content

Commit

Permalink
Update to release 2.0.3
Browse files Browse the repository at this point in the history
- Fixed #26
- Improved wallpapers section
  • Loading branch information
danimahardhika authored Feb 27, 2017
1 parent bcb505d commit 5dd9f57
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public class CandyBarMainActivity extends AppCompatActivity implements AppBarLay
public static List<Request> sMissingApps;
public static List<Icon> sSections;
public static int sIconsCount = 0;
public static boolean sRszIoAvailable;

private static final String TAG_HOME = "home";
private static final String TAG_APPLY = "apply";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@
public class CandyBarSplashActivity extends AppCompatActivity {

private Class<?> mMainActivity;
private AsyncTask<Void, Void, Boolean> mPrepareIconsList;
private AsyncTask<Void, Void, Boolean> mPrepareIconRequest;
private AsyncTask<Void, Void, Boolean> mCheckRszIo;
private AsyncTask<Void, Void, Boolean> mPrepareCloudWallpapers;
private AsyncTask<Void, Void, Boolean> mPrepareIconsList;

public void initSplashActivity(Bundle savedInstanceState, Class<?> mainActivity) {
super.onCreate(savedInstanceState);
Expand All @@ -60,11 +61,12 @@ public void initSplashActivity(Bundle savedInstanceState, Class<?> mainActivity)
int titleColor = ColorHelper.getTitleTextColor(ContextCompat
.getColor(this, R.color.splashColor));
TextView splashTitle = (TextView) findViewById(R.id.splash_title);
splashTitle.setTextColor(ColorHelper.setColorAlpha(titleColor, 0.6f ));
splashTitle.setTextColor(ColorHelper.setColorAlpha(titleColor, 0.6f));

prepareIconsList();
prepareIconRequest(this);
checkRszIo();
prepareCloudWallpapers(this);
loadIconsList();
}

@Override
Expand All @@ -73,13 +75,54 @@ protected void attachBaseContext(Context newBase) {
}

@Override
protected void onDestroy() {
public void onBackPressed() {
if (mPrepareIconRequest != null) mPrepareIconRequest.cancel(true);
if (mPrepareCloudWallpapers != null) mPrepareCloudWallpapers.cancel(true);
if (mCheckRszIo != null) mCheckRszIo.cancel(true);
super.onBackPressed();
}

@Override
protected void onDestroy() {
if (mPrepareIconsList != null) mPrepareIconsList.cancel(true);
super.onDestroy();
}

private void prepareIconsList() {
mPrepareIconsList = new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... voids) {
while (!isCancelled()) {
try {
Thread.sleep(1);
CandyBarMainActivity.sSections = IconsHelper
.getIconsList(CandyBarSplashActivity.this);

int count = 0;
for (Icon section : CandyBarMainActivity.sSections) {
count += section.getIcons().size();
}
CandyBarMainActivity.sIconsCount = count;
return true;
} catch (Exception e) {
Log.d(Tag.LOG_TAG, Log.getStackTraceString(e));
return false;
}
}
return false;
}

@Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
mPrepareIconsList = null;
startActivity(new Intent(CandyBarSplashActivity.this, mMainActivity));
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

private void prepareIconRequest(@NonNull Context context) {
mPrepareIconRequest = new AsyncTask<Void, Void, Boolean>() {

Expand Down Expand Up @@ -110,31 +153,20 @@ protected void onPostExecute(Boolean aBoolean) {
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

private void prepareCloudWallpapers(@NonNull Context context) {
final String wallpaperUrl = getResources().getString(R.string.wallpaper_json);
private void checkRszIo() {
mCheckRszIo = new AsyncTask<Void, Void, Boolean>() {

final String rszio = "https://rsz.io/";

mPrepareCloudWallpapers = new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... voids) {
while (!isCancelled()) {
while ((!isCancelled())) {
try {
Thread.sleep(1);
if (WallpaperHelper.getWallpaperType(context) != WallpaperHelper.CLOUD_WALLPAPERS)
return true;

Database database = new Database(context);
if (database.getWallpapersCount() > 0) return true;

URL url = new URL(wallpaperUrl);
URL url = new URL(rszio);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(15000);
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream stream = connection.getInputStream();
WallpaperJSON wallpapersJSON = LoganSquare.parse(stream, WallpaperJSON.class);
if (database.getWallpapersCount() > 0) database.deleteWallpapers();
database.addWallpapers(wallpapersJSON);
}
return true;
int code = connection.getResponseCode();
return code == 200;
} catch (Exception e) {
Log.d(Tag.LOG_TAG, Log.getStackTraceString(e));
return false;
Expand All @@ -146,26 +178,37 @@ protected Boolean doInBackground(Void... voids) {
@Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
mPrepareCloudWallpapers = null;
CandyBarMainActivity.sRszIoAvailable = aBoolean;
Log.d(Tag.LOG_TAG, "rsz.io availability: " +CandyBarMainActivity.sRszIoAvailable);
mCheckRszIo = null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

private void loadIconsList() {
mPrepareIconsList = new AsyncTask<Void, Void, Boolean>() {
private void prepareCloudWallpapers(@NonNull Context context) {
final String wallpaperUrl = getResources().getString(R.string.wallpaper_json);

mPrepareCloudWallpapers = new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... voids) {
while (!isCancelled()) {
try {
Thread.sleep(1);
CandyBarMainActivity.sSections = IconsHelper
.getIconsList(CandyBarSplashActivity.this);
if (WallpaperHelper.getWallpaperType(context) != WallpaperHelper.CLOUD_WALLPAPERS)
return true;

int count = 0;
for (Icon section : CandyBarMainActivity.sSections) {
count += section.getIcons().size();
Database database = new Database(context);
if (database.getWallpapersCount() > 0) return true;

URL url = new URL(wallpaperUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(15000);
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream stream = connection.getInputStream();
WallpaperJSON wallpapersJSON = LoganSquare.parse(stream, WallpaperJSON.class);
if (database.getWallpapersCount() > 0) database.deleteWallpapers();
database.addWallpapers(wallpapersJSON);
}
CandyBarMainActivity.sIconsCount = count;
return true;
} catch (Exception e) {
Log.d(Tag.LOG_TAG, Log.getStackTraceString(e));
Expand All @@ -178,12 +221,9 @@ protected Boolean doInBackground(Void... voids) {
@Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
mPrepareIconsList = null;
startActivity(new Intent(CandyBarSplashActivity.this, mMainActivity));
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
mPrepareCloudWallpapers = null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -322,5 +322,4 @@ private void OnWallpaperLoaded(@ColorInt int textColor) {
CandyBarWallpaperActivity.this, R.drawable.ic_fab_apply, textColor));
Animator.showFab(mFab);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.dm.material.dashboard.candybar.fragments.dialog.WallpaperOptionsFragment;
import com.dm.material.dashboard.candybar.helpers.ColorHelper;
import com.dm.material.dashboard.candybar.helpers.DrawableHelper;
import com.dm.material.dashboard.candybar.helpers.WallpaperHelper;
import com.dm.material.dashboard.candybar.items.Wallpaper;
import com.dm.material.dashboard.candybar.utils.ImageConfig;
import com.kogitune.activitytransition.ActivityTransitionLauncher;
Expand Down Expand Up @@ -104,8 +105,13 @@ public void onBindViewHolder(ViewHolder holder, int position) {
holder.author.setText(mWallpapers.get(position).getAuthor());
}

ImageLoader.getInstance().displayImage(mWallpapers.get(position).getThumbUrl(), new ImageViewAware(holder.image),
mOptions.build(), ImageConfig.getTargetSize(mContext), new SimpleImageLoadingListener() {
String url = WallpaperHelper.getThumbnailUrl(mContext,
mWallpapers.get(position).getURL(),
mWallpapers.get(position).getThumbUrl());
//Log.d(Tag.LOG_TAG, "loading wallpaper thumbnail: " +url);

ImageLoader.getInstance().displayImage(url, new ImageViewAware(holder.image),
mOptions.build(), ImageConfig.getThumbnailSize(mContext), new SimpleImageLoadingListener() {
long start;
@Override
public void onLoadingStarted(String imageUri, View view) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public void onAnimationStart(Animation animation) {

@Override
public void onAnimationEnd(Animation animation) {
if (getActivity() == null) return;

Animator.startAlphaAnimation(getActivity().findViewById(R.id.shadow), 200, View.VISIBLE);
getIcons();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.view.View;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.afollestad.materialdialogs.MaterialDialog;
Expand Down Expand Up @@ -109,7 +108,9 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity());
builder.customView(R.layout.fragment_inapp_dialog, false)
builder.title(mType == InAppBillingHelper.DONATE ?
R.string.navigation_view_donate : R.string.premium_request)
.customView(R.layout.fragment_inapp_dialog, false)
.positiveText(mType == InAppBillingHelper.DONATE ?
R.string.donate : R.string.premium_request_buy)
.negativeText(R.string.close)
Expand All @@ -131,12 +132,8 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
dialog.show();
setCancelable(false);

TextView header = (TextView) dialog.findViewById(R.id.header);
mInAppList = (ListView) dialog.findViewById(R.id.inapp_list);
mProgress = (ProgressBar) dialog.findViewById(R.id.progress);

header.setText(mType == InAppBillingHelper.DONATE ?
R.string.navigation_view_donate : R.string.premium_request);
return dialog;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ public static void showPremiumRequestExist(@NonNull Context context) {
public static void checkPiracyApp(@NonNull Context context) {
boolean premiumRequest = context.getResources().getBoolean(R.bool.enable_premium_request);
//Dashboard don't need to check piracy app if premium request is disabled
if (!premiumRequest) return;
if (!premiumRequest) {
RequestListener listener = (RequestListener) context;
listener.OnPiracyAppChecked(false);
return;
}

//Lucky Patcher and Freedom package name
String[] strings = new String[] {
Expand Down Expand Up @@ -239,9 +243,7 @@ public static void checkPiracyApp(@NonNull Context context) {

Preferences.getPreferences(context).setPremiumRequestEnabled(!isPiracyAppInstalled);

try {
RequestListener listener = (RequestListener) context;
listener.OnPiracyAppChecked(isPiracyAppInstalled);
} catch (Exception ignored) {}
RequestListener listener = (RequestListener) context;
listener.OnPiracyAppChecked(isPiracyAppInstalled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,6 @@ public static void removeSearchViewSearchIcon(@Nullable View view) {
}
}

public static void changeSearchViewActionModeColor(@NonNull Context context, @Nullable View view,
@AttrRes int original, @AttrRes int target) {
if (view != null) {
CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) view;
int originalColor = ColorHelper.getAttributeColor(context, original);
int targetColor = ColorHelper.getAttributeColor(context, target);

ColorDrawable cd1 = new ColorDrawable(originalColor);
ColorDrawable cd2 = new ColorDrawable(targetColor);

TransitionDrawable td = new TransitionDrawable(new Drawable[]{cd1, cd2});
collapsingToolbar.setContentScrim(td);
td.startTransition(200);
}
}

public static void resetSpanCount(@NonNull Context context, @NonNull RecyclerView recyclerView, @IntegerRes int id) {
try {
GridLayoutManager manager = (GridLayoutManager) recyclerView.getLayoutManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import com.afollestad.materialdialogs.MaterialDialog;
import com.dm.material.dashboard.candybar.R;
import com.dm.material.dashboard.candybar.activities.CandyBarMainActivity;
import com.dm.material.dashboard.candybar.utils.ImageConfig;
import com.dm.material.dashboard.candybar.utils.Tag;
import com.nostra13.universalimageloader.core.ImageLoader;
Expand Down Expand Up @@ -80,6 +81,19 @@ public static int getWallpaperType(@NonNull Context context) {
return UNKNOWN;
}

public static String getThumbnailUrl(@NonNull Context context, String url, String thumbUrl) {
if (thumbUrl.equals(url) && CandyBarMainActivity.sRszIoAvailable) {
return getRszIoThumbnailUrl(context, url);
}
return thumbUrl;
}

private static String getRszIoThumbnailUrl(@NonNull Context context, String url) {
url = url.replaceFirst("https://|http://", "");
ImageSize imageSize = ImageConfig.getThumbnailSize(context); return "https://rsz.io/" +url+ "?width=" +imageSize.getWidth();

}

public static void launchExternalApp(@NonNull Context context) {
String packageName = context.getResources().getString(R.string.wallpaper_json);

Expand Down Expand Up @@ -231,6 +245,8 @@ protected void onProgressUpdate(Integer... values) {
@Override
protected void onCancelled() {
super.onCancelled();
if (file != null) file.delete();

Toast.makeText(context,
context.getResources().getString(R.string.wallpaper_download_cancelled),
Toast.LENGTH_LONG).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public String getURL() {
public boolean equals(Object object) {
boolean equals = false;
if (object != null && object instanceof Wallpaper) {
equals = mUrl.equals(((Wallpaper) object).getURL());
equals = mUrl.equals(((Wallpaper) object).getURL()) &&
mThumbUrl.equals(((Wallpaper) object).getThumbUrl());
}
return equals;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static DisplayImageOptions getWallpaperOptions() {
options.delayBeforeLoading(10)
.bitmapConfig(Bitmap.Config.ARGB_8888)
.imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
.cacheOnDisk(false)
.cacheOnDisk(true)
.cacheInMemory(false);
return options.build();
}
Expand All @@ -88,11 +88,10 @@ public static DisplayImageOptions.Builder getRawImageOptions() {
return options;
}

public static ImageSize getTargetSize(@NonNull Context context) {
public static ImageSize getThumbnailSize(@NonNull Context context) {
int quality = context.getResources().getInteger(R.integer.wallpaper_grid_preview_quality);
if (quality <= 0) quality = 1;
return new ImageSize((50 * quality), (50 * quality));
}

}

Loading

0 comments on commit 5dd9f57

Please sign in to comment.