diff --git a/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardActivity.java b/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardActivity.java index c5ee1901..74283540 100644 --- a/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardActivity.java +++ b/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardActivity.java @@ -7,13 +7,12 @@ import android.content.res.ColorStateList; import android.content.res.Configuration; import android.graphics.Color; -import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.AppBarLayout; -import android.support.design.widget.CollapsingToolbarLayout; import android.support.design.widget.NavigationView; import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; @@ -27,7 +26,6 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.graphics.drawable.DrawerArrowDrawable; import android.support.v7.widget.Toolbar; -import android.view.Menu; import android.view.View; import android.webkit.URLUtil; import android.widget.ImageView; @@ -57,6 +55,7 @@ import com.dm.wallpaper.board.services.WallpaperBoardService; import com.dm.wallpaper.board.utils.Extras; import com.dm.wallpaper.board.utils.ImageConfig; +import com.dm.wallpaper.board.utils.LogUtil; import com.dm.wallpaper.board.utils.listeners.InAppBillingListener; import com.dm.wallpaper.board.utils.listeners.SearchListener; import com.dm.wallpaper.board.utils.listeners.WallpaperBoardListener; @@ -97,6 +96,8 @@ public class WallpaperBoardActivity extends AppCompatActivity implements Activit NavigationView mNavigationView; @BindView(R2.id.drawer_layout) DrawerLayout mDrawerLayout; + @BindView(R2.id.appbar) + AppBarLayout mAppBar; private BillingProcessor mBillingProcessor; private ActionBarDrawerToggle mDrawerToggle; @@ -119,9 +120,10 @@ public void initMainActivity(@Nullable Bundle savedInstanceState, boolean isLice super.onCreate(savedInstanceState); setContentView(R.layout.activity_wallpaper_board); ButterKnife.bind(this); - ViewHelper.setApplicationWindowColor(this); + ViewHelper.resetNavigationBarTranslucent(this, getResources().getConfiguration().orientation); + ColorHelper.setStatusBarIconColor(this); registerBroadcastReceiver(); SoftKeyboardHelper softKeyboardHelper = new SoftKeyboardHelper(this, @@ -133,34 +135,31 @@ public void initMainActivity(@Nullable Bundle savedInstanceState, boolean isLice mDonationProductsId = donationProductsId; Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar); - AppBarLayout appBar = ButterKnife.findById(this, R.id.appbar); toolbar.setTitle(""); + + ViewHelper.setupToolbar(toolbar, true); setSupportActionBar(toolbar); - appBar.setExpanded(false); initNavigationView(toolbar); initNavigationViewHeader(); - initTheme(); initInAppBilling(); mPosition = mLastPosition = 0; if (savedInstanceState != null) { - mPosition = mLastPosition = savedInstanceState.getInt("position", 0); + mPosition = mLastPosition = savedInstanceState.getInt(Extras.EXTRA_POSITION, 0); } setFragment(getFragment(mPosition)); - checkWallpapers(); - if (Preferences.getPreferences(this).isFirstRun()) { - if (isLicenseCheckerEnabled) { - LicenseHelper.getLicenseChecker(this).checkLicense(mLicenseKey, salt); - return; - } + if (Preferences.getPreferences(this).isFirstRun() && isLicenseCheckerEnabled) { + LicenseHelper.getLicenseChecker(this).checkLicense(mLicenseKey, salt); + return; } - if (isLicenseCheckerEnabled) { - if (!Preferences.getPreferences(this).isLicensed()) - finish(); + checkWallpapers(); + + if (isLicenseCheckerEnabled && !Preferences.getPreferences(this).isLicensed()) { + finish(); } } @@ -191,12 +190,6 @@ protected void onDestroy() { super.onDestroy(); } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - ViewHelper.disableAppBarDrag(ButterKnife.findById(this, R.id.appbar)); - return super.onCreateOptionsMenu(menu); - } - @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); @@ -215,6 +208,12 @@ public void onBackPressed() { mDrawerLayout.closeDrawers(); return; } + + if (!mFragmentTag.equals(Extras.TAG_WALLPAPERS)) { + mPosition = mLastPosition = 0; + setFragment(getFragment(mPosition)); + return; + } super.onBackPressed(); } @@ -243,8 +242,19 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis } @Override - public void OnWallpapersChecked(@Nullable Intent intent) { + public void onWallpapersChecked(@Nullable Intent intent) { if (intent != null) { + String packageName = intent.getStringExtra("packageName"); + LogUtil.d("Broadcast received from service with packageName: " +packageName); + + if (packageName == null) + return; + + if (!packageName.equals(getPackageName())) { + LogUtil.d("Received broadcast from different packageName, expected: " +getPackageName()); + return; + } + int size = intent.getIntExtra(Extras.EXTRA_SIZE, 0); Database database = new Database(this); int offlineSize = database.getWallpapersCount(); @@ -279,18 +289,18 @@ public void OnWallpapersChecked(@Nullable Intent intent) { } @Override - public void OnInAppBillingInitialized(boolean success) { + public void onInAppBillingInitialized(boolean success) { if (!success) mBillingProcessor = null; } @Override - public void OnInAppBillingSelected(InAppBilling product) { + public void onInAppBillingSelected(InAppBilling product) { if (mBillingProcessor == null) return; mBillingProcessor.purchase(this, product.getProductId()); } @Override - public void OnInAppBillingConsume(String productId) { + public void onInAppBillingConsume(String productId) { if (mBillingProcessor == null) return; if (mBillingProcessor.consumePurchase(productId)) { new MaterialDialog.Builder(this) @@ -302,26 +312,17 @@ public void OnInAppBillingConsume(String productId) { } @Override - public void OnSearchExpanded(boolean expand) { + public void onSearchExpanded(boolean expand) { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) - findViewById(R.id.collapsing_toolbar); if (expand) { - int color = ColorHelper.getAttributeColor(this, R.attr.search_toolbar_color); - ViewHelper.changeSearchViewActionModeColor(this, - collapsingToolbar, R.attr.toolbar_color, R.attr.search_toolbar_color); - ColorHelper.setStatusBarColor(this, color); - - int iconColor = ColorHelper.getAttributeColor(this, R.attr.search_toolbar_icon); + int icon = ColorHelper.getAttributeColor(this, R.attr.toolbar_icon); toolbar.setNavigationIcon(DrawableHelper.getTintedDrawable( - this, R.drawable.ic_toolbar_back, iconColor)); + this, R.drawable.ic_toolbar_back, icon)); toolbar.setNavigationOnClickListener(view -> onBackPressed()); } else { SoftKeyboardHelper.closeKeyboard(this); - ColorHelper.setTransparentStatusBar(this, Color.TRANSPARENT); - collapsingToolbar.setContentScrim(new ColorDrawable( - ColorHelper.getAttributeColor(this, R.attr.toolbar_color))); + mDrawerToggle.setDrawerArrowDrawable(new DrawerArrowDrawable(this)); toolbar.setNavigationOnClickListener(view -> mDrawerLayout.openDrawer(GravityCompat.START)); @@ -367,6 +368,11 @@ public void onDrawerClosed(View drawerView) { getResources().getBoolean(R.bool.enable_donation)); mNavigationView.setItemTextColor(colorStateList); mNavigationView.setItemIconTintList(colorStateList); + Drawable background = ContextCompat.getDrawable(this, + Preferences.getPreferences(this).isDarkTheme() ? + R.drawable.navigation_view_item_background_dark : + R.drawable.navigation_view_item_background); + mNavigationView.setItemBackground(background); mNavigationView.setNavigationItemSelectedListener(item -> { int id = item.getItemId(); if (id == R.id.navigation_view_wallpapers) mPosition = 0; @@ -381,12 +387,6 @@ public void onDrawerClosed(View drawerView) { }); } - private void initTheme() { - getWindow().getDecorView().setBackgroundColor( - ColorHelper.getAttributeColor(this, R.attr.main_background)); - ColorHelper.setStatusBarIconColor(this); - } - private void initNavigationViewHeader() { String imageUrl = getResources().getString(R.string.navigation_view_header); String titleText = getResources().getString(R.string.navigation_view_header_title); @@ -417,7 +417,7 @@ private void initNavigationViewHeader() { } ImageLoader.getInstance().displayImage(imageUrl, new ImageViewAware(image), - ImageConfig.getDefaultImageOptions(true), new ImageSize(720, 720), null, null); + ImageConfig.getDefaultImageOptions(), new ImageSize(720, 720), null, null); } private void initInAppBilling() { @@ -448,7 +448,7 @@ private void checkWallpapers() { int size = Preferences.getPreferences(this).getAvailableWallpapersCount(); if (size > 0) { - OnWallpapersChecked(new Intent().putExtra(Extras.EXTRA_SIZE, size)); + onWallpapersChecked(new Intent().putExtra(Extras.EXTRA_SIZE, size)); } } @@ -468,9 +468,11 @@ private void setFragment(Fragment fragment) { if (fragment == null) return; clearBackStack(); + mAppBar.setExpanded(true); + FragmentTransaction ft = mFragManager.beginTransaction().replace( R.id.container, fragment, mFragmentTag); - ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); + //ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); try { ft.commit(); } catch (Exception e) { @@ -508,7 +510,7 @@ private void resetToolbarLogo() { private void clearBackStack() { if (mFragManager.getBackStackEntryCount() > 0) { mFragManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); - OnSearchExpanded(false); + onSearchExpanded(false); } } } diff --git a/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardMuzeiActivity.java b/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardMuzeiActivity.java index 12251b29..939da908 100644 --- a/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardMuzeiActivity.java +++ b/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardMuzeiActivity.java @@ -82,7 +82,7 @@ public void initMuzeiActivity(@Nullable Bundle savedInstanceState, @NonNull Clas ViewCompat.setNestedScrollingEnabled(mScrollView, false); ViewHelper.disableTranslucentNavigationBar(this); ColorHelper.setStatusBarColor(this, - ColorHelper.getAttributeColor(this, R.attr.toolbar_color)); + ColorHelper.getAttributeColor(this, R.attr.colorPrimary)); ColorHelper.setStatusBarIconColor(this); ColorHelper.setNavigationBarColor(this, ColorHelper.getDarkerColor( ColorHelper.getAttributeColor(this, R.attr.colorAccent), 0.8f)); @@ -117,8 +117,7 @@ protected void attachBaseContext(Context newBase) { @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - ViewHelper.resetNavigationBarBottomPadding(this, mScrollView, - getResources().getConfiguration().orientation); + ViewHelper.resetViewBottomPadding(mScrollView, false); } @Override @@ -149,7 +148,7 @@ public void onClick(View view) { } @Override - public void OnRefreshDurationSet(int rotateTime, boolean isMinute) { + public void onRefreshDurationSet(int rotateTime, boolean isMinute) { mRotateTime = rotateTime; mIsMinute = isMinute; initRefreshDuration(); diff --git a/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardPreviewActivity.java b/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardPreviewActivity.java index 4ba90931..5e7e6e62 100644 --- a/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardPreviewActivity.java +++ b/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardPreviewActivity.java @@ -32,6 +32,7 @@ import android.widget.TextView; import com.danimahardhika.cafebar.CafeBar; +import com.danimahardhika.cafebar.CafeBarTheme; import com.dm.wallpaper.board.R; import com.dm.wallpaper.board.R2; import com.dm.wallpaper.board.adapters.WallpapersAdapter; @@ -107,15 +108,15 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.activity_wallpaper_preview); ButterKnife.bind(this); ViewHelper.setApplicationWindowColor(this); - ViewHelper.resetNavigationBarTranslucent(this, - getResources().getConfiguration().orientation); + ViewHelper.resetViewBottomMargin(mFab); + ColorHelper.setTransparentStatusBar(this, + ContextCompat.getColor(this, R.color.wallpaperStatusBar)); mIsEnter = true; Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar); TextView toolbarTitle = ButterKnife.findById(this, R.id.toolbar_title); TextView toolbarSubTitle = ButterKnife.findById(this, R.id.toolbar_subtitle); - ColorHelper.setTransparentStatusBar(this, - ContextCompat.getColor(this, R.color.wallpaperStatusBar)); + mColor = ColorHelper.getAttributeColor(this, R.attr.colorAccent); mProgress.getIndeterminateDrawable().setColorFilter(mColor, PorterDuff.Mode.SRC_IN); @@ -159,8 +160,7 @@ public void onTransitionStart(Transition transition) { public void onTransitionEnd(Transition transition) { if (mIsEnter) { mIsEnter = false; - Animator.startSlideDownAnimation(WallpaperBoardPreviewActivity.this, - toolbar, null); + Animator.startSlideDownAnimation(toolbar, View.VISIBLE); loadWallpaper(mUrl); } } @@ -197,7 +197,7 @@ public void onTransitionResume(Transition transition) { @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - ViewHelper.resetNavigationBarTranslucent(this, newConfig.orientation); + ViewHelper.resetViewBottomMargin(mFab); } @Override @@ -249,11 +249,10 @@ public boolean onOptionsItemSelected(MenuItem item) { if (target.exists()) { CafeBar.builder(this) - .to(findViewById(R.id.rootview)) + .theme(new CafeBarTheme.Custom(ColorHelper.getAttributeColor(this, R.attr.card_background))) .autoDismiss(false) - .swipeToDismiss(false) - .floating(true) .maxLines(4) + .fitSystemWindow(true) .content(String.format(getResources().getString(R.string.wallpaper_download_exist), ("\"" +mName + FileHelper.IMAGE_EXTENSION+ "\""))) .icon(R.drawable.ic_toolbar_download) @@ -331,7 +330,7 @@ public void onLoadingFailed(String imageUri, View view, FailReason failReason) { int color = ColorHelper.getAttributeColor( WallpaperBoardPreviewActivity.this, R.attr.main_background); - FrameLayout container = (FrameLayout) findViewById(R.id.container); + FrameLayout container = ButterKnife.findById(WallpaperBoardPreviewActivity.this, R.id.container); ObjectAnimator colorFade = ObjectAnimator.ofObject( container, "backgroundColor", new ArgbEvaluator(), Color.TRANSPARENT, color); @@ -353,9 +352,7 @@ public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { int color = palette.getVibrantColor(accent); mColor = color; int text = ColorHelper.getTitleTextColor(color); - mFab.setBackgroundTintList(ColorHelper.getColorStateList( - android.R.attr.state_pressed, - color, ColorHelper.getDarkerColor(color, 0.9f))); + mFab.setBackgroundTintList(ColorHelper.getColorStateList(color)); OnWallpaperLoaded(text); }); } diff --git a/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardSplashActivity.java b/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardSplashActivity.java index 069f9be9..5f8fece9 100644 --- a/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardSplashActivity.java +++ b/library/src/main/java/com/dm/wallpaper/board/activities/WallpaperBoardSplashActivity.java @@ -2,7 +2,6 @@ import android.content.Context; import android.content.Intent; -import android.graphics.PorterDuff; import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; @@ -10,19 +9,15 @@ import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.util.Log; -import android.view.View; -import android.widget.ProgressBar; import android.widget.TextView; import com.dm.wallpaper.board.R; -import com.dm.wallpaper.board.R2; import com.dm.wallpaper.board.helpers.ColorHelper; -import com.dm.wallpaper.board.utils.Extras; +import com.dm.wallpaper.board.utils.LogUtil; import java.net.HttpURLConnection; import java.net.URL; -import butterknife.BindView; import butterknife.ButterKnife; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; @@ -46,11 +41,9 @@ public class WallpaperBoardSplashActivity extends AppCompatActivity { - @BindView(R2.id.progress) - ProgressBar mProgress; - private Class mMainActivity; private AsyncTask mCheckRszIo; + private AsyncTask mPrepareApp; @Deprecated public void initSplashActivity(@Nullable Bundle savedInstanceState, @NonNull Class mainActivity, int duration) { @@ -60,23 +53,14 @@ public void initSplashActivity(@Nullable Bundle savedInstanceState, @NonNull Cla public void initSplashActivity(@Nullable Bundle savedInstanceState, @NonNull Class mainActivity) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); - ButterKnife.bind(this); mMainActivity = mainActivity; - mProgress.getIndeterminateDrawable().setColorFilter(ColorHelper.getAttributeColor( - this, R.attr.colorAccent), PorterDuff.Mode.SRC_IN); - int color = ContextCompat.getColor(this, R.color.splashColor); int titleColor = ColorHelper.getTitleTextColor(color); TextView splashTitle = ButterKnife.findById(this, R.id.splash_title); - splashTitle.setTextColor(ColorHelper.setColorAlpha(titleColor, 0.6f )); - - TextView splashLoading = ButterKnife.findById(this, R.id.splash_loading); - splashLoading.setTextColor(titleColor); - splashLoading.setText(String.format( - getResources().getString(R.string.splash_screen_loading), - getResources().getString(R.string.app_name))); + splashTitle.setTextColor(ColorHelper.setColorAlpha(titleColor, 0.6f)); + prepareApp(); checkRszIo(); } @@ -86,22 +70,52 @@ protected void attachBaseContext(Context newBase) { } @Override - protected void onDestroy() { + public void onBackPressed() { if (mCheckRszIo != null) mCheckRszIo.cancel(true); + super.onBackPressed(); + } + + @Override + protected void onDestroy() { + if (mPrepareApp != null) mPrepareApp.cancel(true); super.onDestroy(); } + private void prepareApp() { + mPrepareApp = new AsyncTask() { + @Override + protected Boolean doInBackground(Void... voids) { + while (!isCancelled()) { + try { + Thread.sleep(500); + return true; + } catch (Exception e) { + LogUtil.e(Log.getStackTraceString(e)); + return false; + } + } + return null; + } + + @Override + protected void onPostExecute(Boolean aBoolean) { + super.onPostExecute(aBoolean); + if (aBoolean) { + mPrepareApp = null; + + startActivity(new Intent(WallpaperBoardSplashActivity.this, mMainActivity)); + overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); + finish(); + } + } + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + private void checkRszIo() { mCheckRszIo = new AsyncTask() { final String rszio = "https://rsz.io/"; - @Override - protected void onPreExecute() { - super.onPreExecute(); - mProgress.setVisibility(View.VISIBLE); - } - @Override protected Boolean doInBackground(Void... voids) { while ((!isCancelled())) { @@ -114,7 +128,7 @@ protected Boolean doInBackground(Void... voids) { int code = connection.getResponseCode(); return code == 200; } catch (Exception e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); return false; } } @@ -124,14 +138,11 @@ protected Boolean doInBackground(Void... voids) { @Override protected void onPostExecute(Boolean aBoolean) { super.onPostExecute(aBoolean); - WallpaperBoardActivity.sRszIoAvailable = aBoolean; - Log.d(Extras.LOG_TAG, "rsz.io availability: " +WallpaperBoardActivity.sRszIoAvailable); mCheckRszIo = null; - startActivity(new Intent(WallpaperBoardSplashActivity.this, mMainActivity)); - overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); - finish(); + WallpaperBoardActivity.sRszIoAvailable = aBoolean; + LogUtil.e("rsz.io availability: " +WallpaperBoardActivity.sRszIoAvailable); } - }.execute(); + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } diff --git a/library/src/main/java/com/dm/wallpaper/board/adapters/AboutAdapter.java b/library/src/main/java/com/dm/wallpaper/board/adapters/AboutAdapter.java new file mode 100644 index 00000000..1e1b2d5a --- /dev/null +++ b/library/src/main/java/com/dm/wallpaper/board/adapters/AboutAdapter.java @@ -0,0 +1,277 @@ +package com.dm.wallpaper.board.adapters; + +import android.content.ActivityNotFoundException; +import android.content.Context; +import android.content.Intent; +import android.graphics.Color; +import android.net.Uri; +import android.support.annotation.NonNull; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.AppCompatButton; +import android.support.v7.widget.RecyclerView; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.URLUtil; +import android.widget.ImageView; +import android.widget.TextView; + +import com.dm.wallpaper.board.R; +import com.dm.wallpaper.board.fragments.dialogs.CreditsFragment; +import com.dm.wallpaper.board.fragments.dialogs.LicensesFragment; +import com.dm.wallpaper.board.helpers.ColorHelper; +import com.dm.wallpaper.board.helpers.DrawableHelper; +import com.dm.wallpaper.board.utils.Extras; +import com.dm.wallpaper.board.utils.ImageConfig; +import com.dm.wallpaper.board.utils.LogUtil; +import com.mikhaellopez.circularimageview.CircularImageView; +import com.nostra13.universalimageloader.core.ImageLoader; + +import org.sufficientlysecure.htmltextview.HtmlTextView; + +import butterknife.ButterKnife; + +/* + * Wallpaper Board + * + * Copyright (c) 2017 Dani Mahardhika + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class AboutAdapter extends RecyclerView.Adapter { + + private final Context mContext; + + private int mItemCount; + + private final boolean mCardMode; + private final boolean mShowContributors; + + private static final int TYPE_HEADER = 0; + private static final int TYPE_SUBHEADER = 1; + private static final int TYPE_SUBFOOTER = 2; + private static final int TYPE_FOOTER = 3; + private static final int TYPE_BOTTOM_SHADOW = 4; + + public AboutAdapter(@NonNull Context context, int spanCount) { + mContext = context; + + mItemCount = 3; + mCardMode = (spanCount > 1); + if (!mCardMode) { + mItemCount += 1; + } + + mShowContributors = mContext.getResources().getBoolean(R.bool.show_contributors_dialog); + if (mShowContributors) { + mItemCount += 1; + } + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = null; + if (viewType == TYPE_HEADER) { + view = LayoutInflater.from(mContext).inflate( + R.layout.fragment_about_item_header, parent, false); + } else if (viewType == TYPE_SUBHEADER || viewType == TYPE_SUBFOOTER) { + view = LayoutInflater.from(mContext).inflate( + R.layout.fragment_about_item_sub, parent, false); + } else if (viewType == TYPE_FOOTER) { + view = LayoutInflater.from(mContext).inflate( + R.layout.fragment_about_item_footer, parent, false); + } else if (viewType == TYPE_BOTTOM_SHADOW) { + view = LayoutInflater.from(mContext).inflate( + R.layout.fragment_settings_item_footer, parent, false); + } + return new ViewHolder(view, viewType); + } + + @Override + public void onBindViewHolder(ViewHolder holder, int position) { + if (holder.holderId == TYPE_HEADER) { + String imageUri = mContext.getString(R.string.about_image); + + if (ColorHelper.isValidColor(imageUri)) { + holder.image.setBackgroundColor(Color.parseColor(imageUri)); + } else if (!URLUtil.isValidUrl(imageUri)) { + imageUri = "drawable://" + DrawableHelper.getResourceId(mContext, imageUri); + ImageLoader.getInstance().displayImage(imageUri, holder.image, + ImageConfig.getDefaultImageOptions()); + } else { + ImageLoader.getInstance().displayImage(imageUri, holder.image, + ImageConfig.getDefaultImageOptions()); + } + + String profileUri = mContext.getResources().getString(R.string.about_profile_image); + if (!URLUtil.isValidUrl(profileUri)) { + profileUri = "drawable://" + DrawableHelper.getResourceId(mContext, profileUri); + } + + ImageLoader.getInstance().displayImage(profileUri, holder.profile, + ImageConfig.getDefaultImageOptions()); + } + } + + @Override + public int getItemCount() { + return mItemCount; + } + + @Override + public int getItemViewType(int position) { + if (position == 0) return TYPE_HEADER; + if (position == 1) { + if (mShowContributors) return TYPE_SUBHEADER; + else return TYPE_SUBFOOTER; + } + + if (position == 2) { + if (mShowContributors) return TYPE_SUBFOOTER; + else return TYPE_FOOTER; + } + + if (position == 3 && mShowContributors) return TYPE_FOOTER; + return TYPE_BOTTOM_SHADOW; + } + + class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { + + private ImageView image; + private CircularImageView profile; + + private int holderId; + + public ViewHolder(View itemView, int viewType) { + super(itemView); + if (viewType == TYPE_HEADER) { + image = (ImageView) itemView.findViewById(R.id.image); + profile = (CircularImageView) itemView.findViewById(R.id.profile); + HtmlTextView subtitle = ButterKnife.findById(itemView, R.id.subtitle); + AppCompatButton email = ButterKnife.findById(itemView, R.id.email); + AppCompatButton link1 = ButterKnife.findById(itemView, R.id.link1); + AppCompatButton link2 = ButterKnife.findById(itemView, R.id.link2); + holderId = TYPE_HEADER; + + subtitle.setHtml(mContext.getResources().getString(R.string.about_desc)); + + if (!mCardMode) { + int primary = ColorHelper.getAttributeColor(mContext, R.attr.colorPrimary); + + int card = ColorHelper.getAttributeColor(mContext, R.attr.card_background); + email.setTextColor(ColorHelper.getTitleTextColor(primary)); + link1.setTextColor(ColorHelper.getTitleTextColor(card)); + link2.setTextColor(ColorHelper.getTitleTextColor(card)); + } + + String emailText = mContext.getResources().getString(R.string.about_email); + if (emailText.length() == 0) email.setVisibility(View.GONE); + String link2Text = mContext.getResources().getString(R.string.about_link_2_url); + if (link2Text.length() == 0) link2.setVisibility(View.GONE); + + email.setOnClickListener(this); + link1.setOnClickListener(this); + link2.setOnClickListener(this); + } else if (viewType == TYPE_SUBHEADER) { + TextView title = (TextView) itemView.findViewById(R.id.title); + holderId = TYPE_SUBHEADER; + + int color = ColorHelper.getAttributeColor(mContext, android.R.attr.textColorPrimary); + title.setCompoundDrawablesWithIntrinsicBounds(DrawableHelper.getTintedDrawable( + mContext, R.drawable.ic_toolbar_people, color), null, null, null); + title.setText(mContext.getResources().getString(R.string.about_contributors_title)); + + title.setOnClickListener(this); + } else if (viewType == TYPE_SUBFOOTER) { + TextView title = (TextView) itemView.findViewById(R.id.title); + holderId = TYPE_SUBFOOTER; + + int color = ColorHelper.getAttributeColor(mContext, android.R.attr.textColorPrimary); + title.setCompoundDrawablesWithIntrinsicBounds(DrawableHelper.getTintedDrawable( + mContext, R.drawable.ic_toolbar_licenses, color), null, null, null); + title.setText(mContext.getResources().getString(R.string.about_open_source_licenses)); + + title.setOnClickListener(this); + } else if (viewType == TYPE_FOOTER) { + AppCompatButton link2 = ButterKnife.findById(itemView, R.id.dev_google_plus); + AppCompatButton link1 = ButterKnife.findById(itemView, R.id.dev_github); + holderId = TYPE_FOOTER; + + if (!mCardMode) { + int primary = ColorHelper.getAttributeColor(mContext, R.attr.colorPrimary); + int card = ColorHelper.getAttributeColor(mContext, R.attr.card_background); + link1.setTextColor(ColorHelper.getTitleTextColor(primary)); + link2.setTextColor(ColorHelper.getTitleTextColor(card)); + } + + link1.setOnClickListener(this); + link2.setOnClickListener(this); + } else if (viewType == TYPE_BOTTOM_SHADOW) { + holderId = TYPE_BOTTOM_SHADOW; + } + } + + @Override + public void onClick(View view) { + int id = view.getId(); + if (id == R.id.email) { + try { + final Intent email = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( + "mailto", mContext.getResources().getString( + R.string.about_email), null)); + email.putExtra(Intent.EXTRA_SUBJECT, (mContext.getResources().getString( + R.string.app_name))); + mContext.startActivity(Intent.createChooser(email, + mContext.getResources().getString(R.string.email_client))); + return; + } + catch (ActivityNotFoundException e) { + LogUtil.e(Log.getStackTraceString(e)); + } + return; + } else if (id == R.id.title) { + if (holderId == TYPE_SUBHEADER) { + CreditsFragment.showCreditsDialog( + ((AppCompatActivity) mContext).getSupportFragmentManager(), + Extras.TYPE_CONTRIBUTORS); + } else if (holderId == TYPE_SUBFOOTER) { + LicensesFragment.showLicensesDialog(((AppCompatActivity) mContext).getSupportFragmentManager()); + } + return; + } + + Intent intent = null; + if (id == R.id.link1) { + intent = new Intent(Intent.ACTION_VIEW, Uri.parse( + mContext.getResources().getString(R.string.about_link_1_url))); + } else if (id == R.id.link2) { + intent = new Intent(Intent.ACTION_VIEW, Uri.parse( + mContext.getResources().getString(R.string.about_link_2_url))); + } else if (id == R.id.dev_google_plus) { + intent = new Intent(Intent.ACTION_VIEW, Uri.parse(mContext + .getResources().getString(R.string.about_dashboard_dev_google_plus_url))); + } else if (id == R.id.dev_github) { + intent = new Intent(Intent.ACTION_VIEW, Uri.parse(mContext + .getResources().getString(R.string.about_dashboard_dev_github_url))); + } + + try { + mContext.startActivity(intent); + } catch (NullPointerException | ActivityNotFoundException e) { + LogUtil.e(Log.getStackTraceString(e)); + } + } + } +} diff --git a/library/src/main/java/com/dm/wallpaper/board/adapters/CreditsAdapter.java b/library/src/main/java/com/dm/wallpaper/board/adapters/CreditsAdapter.java index 33d0369f..f8db1a43 100644 --- a/library/src/main/java/com/dm/wallpaper/board/adapters/CreditsAdapter.java +++ b/library/src/main/java/com/dm/wallpaper/board/adapters/CreditsAdapter.java @@ -16,7 +16,7 @@ import com.dm.wallpaper.board.R; import com.dm.wallpaper.board.R2; import com.dm.wallpaper.board.items.Credit; -import com.dm.wallpaper.board.utils.Extras; +import com.dm.wallpaper.board.utils.LogUtil; import java.util.List; @@ -85,7 +85,7 @@ public View getView(int position, View view, ViewGroup viewGroup) { try { mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link))); } catch (ActivityNotFoundException e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); } } }); diff --git a/library/src/main/java/com/dm/wallpaper/board/adapters/SettingsAdapter.java b/library/src/main/java/com/dm/wallpaper/board/adapters/SettingsAdapter.java new file mode 100644 index 00000000..e3ef6c32 --- /dev/null +++ b/library/src/main/java/com/dm/wallpaper/board/adapters/SettingsAdapter.java @@ -0,0 +1,213 @@ +package com.dm.wallpaper.board.adapters; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.AppCompatCheckBox; +import android.support.v7.widget.RecyclerView; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.Toast; + +import com.afollestad.materialdialogs.MaterialDialog; +import com.dm.wallpaper.board.R; +import com.dm.wallpaper.board.helpers.ColorHelper; +import com.dm.wallpaper.board.helpers.DrawableHelper; +import com.dm.wallpaper.board.helpers.FileHelper; +import com.dm.wallpaper.board.items.Setting; +import com.dm.wallpaper.board.preferences.Preferences; +import com.dm.wallpaper.board.utils.LogUtil; + +import java.io.File; +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.List; + +import butterknife.ButterKnife; + +/* + * Wallpaper Board + * + * Copyright (c) 2017 Dani Mahardhika + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class SettingsAdapter extends RecyclerView.Adapter { + + private final Context mContext; + private final List mSettings; + + private static final int TYPE_CONTENT = 0; + private static final int TYPE_FOOTER = 1; + + public SettingsAdapter(@NonNull Context context, @NonNull List settings) { + mContext = context; + mSettings = settings; + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = null; + if (viewType == TYPE_CONTENT) { + view = LayoutInflater.from(mContext).inflate( + R.layout.fragment_settings_item_list, parent, false); + } else if (viewType == TYPE_FOOTER) { + view = LayoutInflater.from(mContext).inflate( + R.layout.fragment_settings_item_footer, parent, false); + } + return new ViewHolder(view, viewType); + } + + @Override + public void onBindViewHolder(ViewHolder holder, int position) { + if (holder.holderId == TYPE_CONTENT) { + Setting setting = mSettings.get(position); + + if (setting.getTitle().length() == 0) { + holder.title.setVisibility(View.GONE); + holder.divider.setVisibility(View.GONE); + holder.container.setVisibility(View.VISIBLE); + + holder.subtitle.setText(setting.getSubtitle()); + + if (setting.getContent().length() == 0) { + holder.content.setVisibility(View.GONE); + } else { + holder.content.setText(setting.getContent()); + holder.content.setVisibility(View.VISIBLE); + } + + if (setting.getFooter().length() == 0) { + holder.footer.setVisibility(View.GONE); + } else { + holder.footer.setText(setting.getFooter()); + } + + if (setting.getCheckState() >= 0) { + holder.checkBox.setVisibility(View.VISIBLE); + holder.checkBox.setChecked(setting.getCheckState() == 1); + } else { + holder.checkBox.setVisibility(View.GONE); + } + } else { + holder.container.setVisibility(View.GONE); + holder.title.setVisibility(View.VISIBLE); + holder.title.setText(setting.getTitle()); + + if (position > 0) { + holder.divider.setVisibility(View.VISIBLE); + } else { + holder.divider.setVisibility(View.GONE); + } + + if (setting.getIcon() != -1) { + int color = ColorHelper.getAttributeColor(mContext, android.R.attr.textColorPrimary); + holder.title.setCompoundDrawablesWithIntrinsicBounds(DrawableHelper.getTintedDrawable( + mContext, setting.getIcon(), color), null, null, null); + } + } + } + } + + @Override + public int getItemCount() { + return mSettings.size() + 1; + } + + @Override + public int getItemViewType(int position) { + if (position == (getItemCount() - 1)) return TYPE_FOOTER; + return TYPE_CONTENT; + } + + class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { + + private TextView title; + private TextView subtitle; + private TextView content; + private TextView footer; + private LinearLayout container; + private AppCompatCheckBox checkBox; + private View divider; + + private int holderId; + + ViewHolder(View itemView, int viewType) { + super(itemView); + if (viewType == TYPE_CONTENT) { + title = ButterKnife.findById(itemView, R.id.title); + subtitle = ButterKnife.findById(itemView, R.id.subtitle); + content = ButterKnife.findById(itemView, R.id.content); + footer = ButterKnife.findById(itemView, R.id.footer); + checkBox = ButterKnife.findById(itemView, R.id.checkbox); + divider = ButterKnife.findById(itemView, R.id.divider); + container = ButterKnife.findById(itemView, R.id.container); + holderId = TYPE_CONTENT; + + container.setOnClickListener(this); + } else if (viewType == TYPE_FOOTER) { + holderId = TYPE_FOOTER; + } + } + + @Override + public void onClick(View view) { + int id = view.getId(); + if (id == R.id.container) { + int position = getAdapterPosition(); + + if (position < 0 || position > mSettings.size()) return; + + Setting setting = mSettings.get(position); + switch (setting.getType()) { + case CACHE: + new MaterialDialog.Builder(mContext) + .content(R.string.pref_data_cache_clear_dialog) + .positiveText(R.string.clear) + .negativeText(android.R.string.cancel) + .onPositive((dialog, which) -> { + try { + File cache = mContext.getCacheDir(); + FileHelper.clearCache(cache); + + double size = (double) FileHelper.getCacheSize( + mContext.getCacheDir()) / FileHelper.MB; + NumberFormat formatter = new DecimalFormat("#0.00"); + + setting.setFooter(String.format(mContext.getResources().getString( + R.string.pref_data_cache_size), + formatter.format(size) + " MB")); + notifyItemChanged(position); + + Toast.makeText(mContext, R.string.pref_data_cache_cleared, + Toast.LENGTH_LONG).show(); + } catch (Exception e) { + LogUtil.e(Log.getStackTraceString(e)); + } + }) + .show(); + break; + case THEME: + Preferences.getPreferences(mContext).setDarkTheme(!checkBox.isChecked()); + ((AppCompatActivity) mContext).recreate(); + break; + } + } + } + } +} diff --git a/library/src/main/java/com/dm/wallpaper/board/adapters/WallpapersAdapter.java b/library/src/main/java/com/dm/wallpaper/board/adapters/WallpapersAdapter.java index 1e196056..f16a9bfa 100644 --- a/library/src/main/java/com/dm/wallpaper/board/adapters/WallpapersAdapter.java +++ b/library/src/main/java/com/dm/wallpaper/board/adapters/WallpapersAdapter.java @@ -21,6 +21,8 @@ import android.widget.LinearLayout; import android.widget.TextView; +import com.danimahardhika.cafebar.CafeBar; +import com.danimahardhika.cafebar.CafeBarTheme; import com.dm.wallpaper.board.R; import com.dm.wallpaper.board.R2; import com.dm.wallpaper.board.activities.WallpaperBoardPreviewActivity; @@ -36,7 +38,8 @@ import com.dm.wallpaper.board.utils.Extras; import com.dm.wallpaper.board.utils.ImageConfig; import com.dm.wallpaper.board.utils.listeners.WallpaperListener; -import com.dm.wallpaper.board.utils.views.WallpaperView; +import com.dm.wallpaper.board.utils.views.HeaderView; + import com.kogitune.activitytransition.ActivityTransitionLauncher; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; @@ -103,7 +106,7 @@ public WallpapersAdapter(@NonNull Context context, @NonNull List wall mContext.getResources().getDimensionPixelSize(R.dimen.default_image_padding)); mOptions = ImageConfig.getRawDefaultImageOptions(); mOptions.resetViewBeforeLoading(true); - mOptions.cacheInMemory(false); + mOptions.cacheInMemory(true); mOptions.cacheOnDisk(true); mOptions.showImageForEmptyUri(failed); mOptions.showImageOnFail(failed); @@ -181,7 +184,7 @@ class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener @BindView(R2.id.container) LinearLayout container; @BindView(R2.id.image) - WallpaperView image; + HeaderView image; @BindView(R2.id.name) TextView name; @BindView(R2.id.author) @@ -226,7 +229,7 @@ public void onClick(View view) { fragment instanceof FavoritesFragment || fragment instanceof WallpaperSearchFragment) { WallpaperListener listener = (WallpaperListener) fragment; - listener.OnWallpaperSelected(position); + listener.onWallpaperSelected(position); } } } @@ -245,6 +248,18 @@ public void onClick(View view) { mWallpapers.get(position).setFavorite(!mWallpapers.get(position).isFavorite()); setFavorite(favorite, name.getCurrentTextColor(), position); + + CafeBar.builder(mContext) + .theme(new CafeBarTheme.Custom(ColorHelper.getAttributeColor( + mContext, R.attr.card_background))) + .fitSystemWindow(R.bool.view_fitsystemwindow) + .content(String.format( + mContext.getResources().getString(mWallpapers.get(position).isFavorite() ? + R.string.wallpaper_favorite_added : R.string.wallpaper_favorite_removed), + mWallpapers.get(position).getName())) + .icon(mWallpapers.get(position).isFavorite() ? + R.drawable.ic_toolbar_love : R.drawable.ic_toolbar_unlove) + .build().show(); } } diff --git a/library/src/main/java/com/dm/wallpaper/board/applications/WallpaperBoardApplication.java b/library/src/main/java/com/dm/wallpaper/board/applications/WallpaperBoardApplication.java index 43656f51..a2d536e6 100644 --- a/library/src/main/java/com/dm/wallpaper/board/applications/WallpaperBoardApplication.java +++ b/library/src/main/java/com/dm/wallpaper/board/applications/WallpaperBoardApplication.java @@ -7,6 +7,7 @@ import com.dm.wallpaper.board.R; import com.dm.wallpaper.board.activities.WallpaperBoardCrashReport; import com.dm.wallpaper.board.utils.ImageConfig; +import com.dm.wallpaper.board.utils.LogUtil; import com.nostra13.universalimageloader.core.ImageLoader; import java.text.SimpleDateFormat; @@ -47,6 +48,9 @@ public void initApplication() { .setFontAttrId(R.attr.fontPath) .build()); + //Enable logging + LogUtil.setLoggingEnabled(true); + if (Patterns.EMAIL_ADDRESS.matcher(getResources().getString(R.string.dev_email)).matches()) { mHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(this::handleUncaughtException); diff --git a/library/src/main/java/com/dm/wallpaper/board/fragments/AboutFragment.java b/library/src/main/java/com/dm/wallpaper/board/fragments/AboutFragment.java index e9123441..d12d35f1 100644 --- a/library/src/main/java/com/dm/wallpaper/board/fragments/AboutFragment.java +++ b/library/src/main/java/com/dm/wallpaper/board/fragments/AboutFragment.java @@ -1,38 +1,22 @@ package com.dm.wallpaper.board.fragments; -import android.content.ActivityNotFoundException; -import android.content.Intent; import android.content.res.Configuration; -import android.graphics.Color; -import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.view.ViewCompat; -import android.support.v4.widget.NestedScrollView; -import android.support.v7.widget.CardView; -import android.util.Log; +import android.support.v7.widget.DefaultItemAnimator; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.StaggeredGridLayoutManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.webkit.URLUtil; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; import com.dm.wallpaper.board.R; import com.dm.wallpaper.board.R2; -import com.dm.wallpaper.board.fragments.dialogs.CreditsFragment; -import com.dm.wallpaper.board.fragments.dialogs.LicensesFragment; -import com.dm.wallpaper.board.helpers.ColorHelper; -import com.dm.wallpaper.board.helpers.DrawableHelper; +import com.dm.wallpaper.board.adapters.AboutAdapter; import com.dm.wallpaper.board.helpers.ViewHelper; -import com.dm.wallpaper.board.utils.Extras; -import com.dm.wallpaper.board.utils.ImageConfig; -import com.mikhaellopez.circularimageview.CircularImageView; -import com.nostra13.universalimageloader.core.ImageLoader; - -import org.sufficientlysecure.htmltextview.HtmlTextView; import butterknife.BindView; import butterknife.ButterKnife; @@ -55,36 +39,10 @@ * limitations under the License. */ -public class AboutFragment extends Fragment implements View.OnClickListener { - - @BindView(R2.id.scrollview) - NestedScrollView mScrollView; - @BindView(R2.id.card_contributors) - CardView mCardContributors; - @BindView(R2.id.contributors) - LinearLayout mContributors; - @BindView(R2.id.contributors_icon) - ImageView mContributorsIcon; - @BindView(R2.id.licenses) - LinearLayout mLicenses; - @BindView(R2.id.licenses_icon) - ImageView mLicensesIcon; - @BindView(R2.id.image) - ImageView mImageView; - @BindView(R2.id.profile) - CircularImageView mProfile; - @BindView(R2.id.about_desc) - HtmlTextView mAboutDesc; - @BindView(R2.id.email) - TextView mEmail; - @BindView(R2.id.link1) - TextView mLink1; - @BindView(R2.id.link2) - TextView mLink2; - @BindView(R2.id.dev_google_plus) - TextView mDevGooglePlus; - @BindView(R2.id.dev_github) - TextView mDevGitHub; +public class AboutFragment extends Fragment { + + @BindView(R2.id.recyclerview) + RecyclerView mRecyclerView; @Nullable @Override @@ -97,122 +55,48 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - ViewCompat.setNestedScrollingEnabled(mScrollView, false); - ViewHelper.resetNavigationBarBottomPadding(getActivity(), mScrollView, - getActivity().getResources().getConfiguration().orientation); - - initImageHeader(); - initProfileImage(); - initAbout(); + ViewCompat.setNestedScrollingEnabled(mRecyclerView, false); + resetRecyclerViewPadding(getActivity().getResources().getConfiguration().orientation); - int color = ColorHelper.getAttributeColor(getActivity(), android.R.attr.textColorPrimary); - - mLicensesIcon.setImageDrawable(DrawableHelper.getTintedDrawable( - getActivity(), R.drawable.ic_toolbar_licenses, color)); - - if (getActivity().getResources().getBoolean(R.bool.show_contributors_dialog)) { - mContributorsIcon.setImageDrawable(DrawableHelper.getTintedDrawable( - getActivity(), R.drawable.ic_toolbar_people, color)); - mContributors.setOnClickListener(this); - mCardContributors.setVisibility(View.VISIBLE); - } + mRecyclerView.setItemAnimator(new DefaultItemAnimator()); - mLicenses.setOnClickListener(this); - - mEmail.setOnClickListener(this); - mLink1.setOnClickListener(this); - mLink2.setOnClickListener(this); - mDevGooglePlus.setOnClickListener(this); - mDevGitHub.setOnClickListener(this); + int spanCount = getActivity().getResources().getInteger(R.integer.about_column_count); + mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager( + spanCount, StaggeredGridLayoutManager.VERTICAL)); + mRecyclerView.setAdapter(new AboutAdapter(getActivity(), spanCount)); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - ViewHelper.resetNavigationBarBottomPadding(getActivity(), mScrollView, - getActivity().getResources().getConfiguration().orientation); - } + resetRecyclerViewPadding(newConfig.orientation); - @Override - public void onClick(View view) { - int id = view.getId(); - if (id == R.id.contributors) { - CreditsFragment.showCreditsDialog(getActivity().getSupportFragmentManager(), Extras.TYPE_CONTRIBUTORS); - return; - } else if (id == R.id.licenses) { - LicensesFragment.showLicensesDialog(getActivity().getSupportFragmentManager()); - return; - } + ViewHelper.resetSpanCount(getActivity(), mRecyclerView, R.integer.about_column_count); - Intent intent = null; - if (id == R.id.email) { - try { - final Intent email = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( - "mailto", getActivity().getResources().getString( - R.string.about_email), null)); - email.putExtra(Intent.EXTRA_SUBJECT, (getActivity().getResources().getString( - R.string.app_name))); - getActivity().startActivity(Intent.createChooser(email, - getActivity().getResources().getString(R.string.email_client))); - return; - } - catch (ActivityNotFoundException e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); - } - return; - } else if (id == R.id.link1) { - intent = new Intent(Intent.ACTION_VIEW, Uri.parse( - getActivity().getResources().getString(R.string.about_link_1_url))); - } else if (id == R.id.link2) { - intent = new Intent(Intent.ACTION_VIEW, Uri.parse( - getActivity().getResources().getString(R.string.about_link_2_url))); - } else if (id == R.id.dev_github) { - intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getActivity() - .getResources().getString(R.string.about_dashboard_dev_github_url))); - } else if (id == R.id.dev_google_plus) { - intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getActivity() - .getResources().getString(R.string.about_dashboard_dev_google_plus_url))); - } - - try { - getActivity().startActivity(intent); - } catch (NullPointerException | ActivityNotFoundException e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); - } - } - - private void initAbout() { - String desc = getActivity().getResources().getString(R.string.about_desc); - mAboutDesc.setHtml(desc); - - String email = getActivity().getResources().getString(R.string.about_email); - if (email.length() == 0) mEmail.setVisibility(View.GONE); - String link2 = getActivity().getResources().getString(R.string.about_link_2_url); - if (link2.length() == 0) mLink2.setVisibility(View.GONE); + StaggeredGridLayoutManager manager = (StaggeredGridLayoutManager) mRecyclerView.getLayoutManager(); + mRecyclerView.setAdapter(new AboutAdapter(getActivity(), manager.getSpanCount())); } - private void initImageHeader() { - String url = getActivity().getString(R.string.about_image); - if (ColorHelper.isValidColor(url)) { - mImageView.setBackgroundColor(Color.parseColor(url)); - return; - } + private void resetRecyclerViewPadding(int orientation) { + if (mRecyclerView == null) return; - if (!URLUtil.isValidUrl(url)) { - url = "drawable://" + DrawableHelper.getResourceId(getActivity(), url); + int padding = 0; + int navBar = 0; + if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + padding = getActivity().getResources().getDimensionPixelSize(R.dimen.content_padding); + navBar = padding; } - ImageLoader.getInstance().displayImage(url, mImageView, - ImageConfig.getDefaultImageOptions(true)); - } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + boolean tabletMode = getActivity().getResources().getBoolean(R.bool.tablet_mode); + if (tabletMode || orientation == Configuration.ORIENTATION_PORTRAIT) { + navBar = ViewHelper.getNavigationBarHeight(getActivity()); + } - private void initProfileImage() { - String url = getActivity().getResources().getString(R.string.about_profile_image); - if (!URLUtil.isValidUrl(url)) { - url = "drawable://" + DrawableHelper.getResourceId(getActivity(), url); + navBar += ViewHelper.getStatusBarHeight(getContext()); } - ImageLoader.getInstance().displayImage(url, mProfile, - ImageConfig.getDefaultImageOptions(true)); + navBar += ViewHelper.getToolbarHeight(getActivity()); + mRecyclerView.setPadding(padding, padding, 0, navBar); } } diff --git a/library/src/main/java/com/dm/wallpaper/board/fragments/FavoritesFragment.java b/library/src/main/java/com/dm/wallpaper/board/fragments/FavoritesFragment.java index e2b82edf..6fecc322 100644 --- a/library/src/main/java/com/dm/wallpaper/board/fragments/FavoritesFragment.java +++ b/library/src/main/java/com/dm/wallpaper/board/fragments/FavoritesFragment.java @@ -5,7 +5,6 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; -import android.support.v4.view.ViewCompat; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.GridLayoutManager; @@ -21,9 +20,8 @@ import com.dm.wallpaper.board.databases.Database; import com.dm.wallpaper.board.helpers.ViewHelper; import com.dm.wallpaper.board.items.Wallpaper; -import com.dm.wallpaper.board.utils.Extras; +import com.dm.wallpaper.board.utils.LogUtil; import com.dm.wallpaper.board.utils.listeners.WallpaperListener; -import com.pluscubed.recyclerfastscroll.RecyclerFastScroller; import java.util.ArrayList; import java.util.List; @@ -53,8 +51,6 @@ public class FavoritesFragment extends Fragment implements WallpaperListener { @BindView(R2.id.recyclerview) RecyclerView mRecyclerView; - @BindView(R2.id.fastscroll) - RecyclerFastScroller mFastScroll; @BindView(R2.id.swipe) SwipeRefreshLayout mSwipe; @@ -71,16 +67,13 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - ViewCompat.setNestedScrollingEnabled(mRecyclerView, false); - ViewHelper.resetNavigationBarBottomPadding(getActivity(), mRecyclerView, - getActivity().getResources().getConfiguration().orientation); + ViewHelper.resetViewBottomPadding(mRecyclerView, true); mSwipe.setEnabled(false); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), - getActivity().getResources().getInteger(R.integer.column_num))); + getActivity().getResources().getInteger(R.integer.wallpapers_column_count))); mRecyclerView.setHasFixedSize(false); - mFastScroll.attachRecyclerView(mRecyclerView); getWallpapers(); } @@ -89,7 +82,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); ViewHelper.resetSpanCount(getActivity(), mRecyclerView); - ViewHelper.resetNavigationBarBottomPadding(getActivity(), mRecyclerView, newConfig.orientation); + ViewHelper.resetViewBottomPadding(mRecyclerView, true); } @Override @@ -99,7 +92,7 @@ public void onDestroy() { } @Override - public void OnWallpaperSelected(int position) { + public void onWallpaperSelected(int position) { if (mRecyclerView == null) return; if (position < 0 || position > mRecyclerView.getAdapter().getItemCount()) return; @@ -126,7 +119,7 @@ protected Boolean doInBackground(Void... voids) { wallpapers = database.getFavoriteWallpapers(); return true; } catch (Exception e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); return false; } } diff --git a/library/src/main/java/com/dm/wallpaper/board/fragments/SettingsFragment.java b/library/src/main/java/com/dm/wallpaper/board/fragments/SettingsFragment.java index f0e4b18c..cff372b5 100644 --- a/library/src/main/java/com/dm/wallpaper/board/fragments/SettingsFragment.java +++ b/library/src/main/java/com/dm/wallpaper/board/fragments/SettingsFragment.java @@ -5,26 +5,26 @@ import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.view.ViewCompat; -import android.support.v4.widget.NestedScrollView; -import android.support.v7.widget.AppCompatCheckBox; -import android.util.Log; +import android.support.v7.widget.DefaultItemAnimator; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; -import com.afollestad.materialdialogs.MaterialDialog; import com.dm.wallpaper.board.R; import com.dm.wallpaper.board.R2; +import com.dm.wallpaper.board.adapters.SettingsAdapter; +import com.dm.wallpaper.board.helpers.FileHelper; import com.dm.wallpaper.board.helpers.ViewHelper; +import com.dm.wallpaper.board.items.Setting; import com.dm.wallpaper.board.preferences.Preferences; -import com.dm.wallpaper.board.utils.Extras; import java.io.File; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; @@ -47,22 +47,10 @@ * limitations under the License. */ -public class SettingsFragment extends Fragment implements View.OnClickListener { +public class SettingsFragment extends Fragment { - @BindView(R2.id.pref_cache_clear) - LinearLayout mCacheClear; - @BindView(R2.id.pref_cache_size) - TextView mCacheSize; - @BindView(R2.id.pref_dark_theme) - LinearLayout mDarkTheme; - @BindView(R2.id.pref_dark_theme_check) - AppCompatCheckBox mDarkThemeCheck; - @BindView(R2.id.pref_walls_directory) - TextView mWallsDirectory; - @BindView(R2.id.scrollview) - NestedScrollView mScrollView; - - private File mCache; + @BindView(R2.id.recyclerview) + RecyclerView mRecyclerView; @Nullable @Override @@ -75,17 +63,11 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - ViewCompat.setNestedScrollingEnabled(mScrollView, false); - ViewHelper.resetNavigationBarBottomPadding(getActivity(), mScrollView, - getActivity().getResources().getConfiguration().orientation); - mCacheClear.setOnClickListener(this); - mDarkTheme.setOnClickListener(this); + ViewCompat.setNestedScrollingEnabled(mRecyclerView, false); + ViewHelper.resetViewBottomPadding(mRecyclerView, false); - if (Preferences.getPreferences(getActivity()).getWallsDirectory().length() > 0) { - String directory = Preferences.getPreferences( - getActivity()).getWallsDirectory() + File.separator; - mWallsDirectory.setText(directory); - } + mRecyclerView.setItemAnimator(new DefaultItemAnimator()); + mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); initSettings(); } @@ -93,73 +75,48 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - ViewHelper.resetNavigationBarBottomPadding(getActivity(), mScrollView, - getActivity().getResources().getConfiguration().orientation); - } - - @Override - public void onClick(View view) { - int id = view.getId(); - if (id == R.id.pref_cache_clear) { - new MaterialDialog.Builder(getActivity()) - .title(R.string.pref_data_cache) - .content(R.string.pref_data_cache_clear_dialog) - .positiveText(R.string.clear) - .negativeText(android.R.string.cancel) - .onPositive((dialog, which) -> { - try { - clearCache(mCache); - initSettings(); - - Toast.makeText(getActivity(), getActivity() - .getResources().getString( - R.string.pref_data_cache_cleared), - Toast.LENGTH_LONG).show(); - } catch (Exception e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); - } - }) - .show(); - } else if (id == R.id.pref_dark_theme) { - Preferences.getPreferences(getActivity()).setDarkTheme(!mDarkThemeCheck.isChecked()); - mDarkThemeCheck.setChecked(!mDarkThemeCheck.isChecked()); - getActivity().recreate(); - } + ViewHelper.resetViewBottomPadding(mRecyclerView, false); } private void initSettings() { - mCache = new File(getActivity().getCacheDir().toString()); + List settings = new ArrayList<>(); - double cache = (double) cacheSize(mCache)/1024/1024; + double cache = (double) FileHelper.getCacheSize(getActivity().getCacheDir()) / FileHelper.MB; NumberFormat formatter = new DecimalFormat("#0.00"); - String cacheSize = getActivity().getResources().getString( - R.string.pref_data_cache_size) - +" "+ (formatter.format(cache)) + " MB"; - mCacheSize.setText(cacheSize); - mDarkThemeCheck.setChecked(Preferences.getPreferences(getActivity()).isDarkTheme()); - } + settings.add(new Setting(R.drawable.ic_toolbar_storage, + getActivity().getResources().getString(R.string.pref_data_header), + "", "", "", Setting.Type.HEADER, -1)); - private void clearCache(File fileOrDirectory) { - if (fileOrDirectory.isDirectory()) - for (File child : fileOrDirectory.listFiles()) - clearCache(child); - fileOrDirectory.delete(); - } + settings.add(new Setting(-1, "", + getActivity().getResources().getString(R.string.pref_data_cache), + getActivity().getResources().getString(R.string.pref_data_cache_desc), + String.format(getActivity().getResources().getString(R.string.pref_data_cache_size), + formatter.format(cache) + " MB"), + Setting.Type.CACHE, -1)); + + settings.add(new Setting(R.drawable.ic_toolbar_theme, + getActivity().getResources().getString(R.string.pref_theme_header), + "", "", "", Setting.Type.HEADER, -1)); + + settings.add(new Setting(-1, "", + getActivity().getResources().getString(R.string.pref_theme_dark), + getActivity().getResources().getString(R.string.pref_theme_dark_desc), + "", Setting.Type.THEME, Preferences.getPreferences(getActivity()).isDarkTheme() ? 1 : 0)); + + settings.add(new Setting(R.drawable.ic_toolbar_wallpapers, + getActivity().getResources().getString(R.string.pref_wallpaper_header), + "", "", "", Setting.Type.HEADER, -1)); - private long cacheSize(File dir) { - if (dir.exists()) { - long result = 0; - File[] fileList = dir.listFiles(); - for (File aFileList : fileList) { - if (aFileList.isDirectory()) { - result += cacheSize(aFileList); - } else { - result += aFileList.length(); - } - } - return result; + String directory = getActivity().getResources().getString(R.string.pref_wallpaper_location_desc); + if (Preferences.getPreferences(getActivity()).getWallsDirectory().length() > 0) { + directory = Preferences.getPreferences(getActivity()).getWallsDirectory() + File.separator; } - return 0; + + settings.add(new Setting(-1, "", + getActivity().getResources().getString(R.string.pref_wallpaper_location), + directory, "", Setting.Type.WALLPAPER, -1)); + + mRecyclerView.setAdapter(new SettingsAdapter(getActivity(), settings)); } } diff --git a/library/src/main/java/com/dm/wallpaper/board/fragments/WallpaperSearchFragment.java b/library/src/main/java/com/dm/wallpaper/board/fragments/WallpaperSearchFragment.java index 7165d9f1..9af70472 100644 --- a/library/src/main/java/com/dm/wallpaper/board/fragments/WallpaperSearchFragment.java +++ b/library/src/main/java/com/dm/wallpaper/board/fragments/WallpaperSearchFragment.java @@ -33,9 +33,8 @@ import com.dm.wallpaper.board.helpers.SoftKeyboardHelper; import com.dm.wallpaper.board.helpers.ViewHelper; import com.dm.wallpaper.board.items.Wallpaper; -import com.dm.wallpaper.board.utils.Extras; +import com.dm.wallpaper.board.utils.LogUtil; import com.dm.wallpaper.board.utils.listeners.WallpaperListener; -import com.pluscubed.recyclerfastscroll.RecyclerFastScroller; import java.util.ArrayList; import java.util.List; @@ -65,8 +64,6 @@ public class WallpaperSearchFragment extends Fragment implements WallpaperListen @BindView(R2.id.recyclerview) RecyclerView mRecyclerView; - @BindView(R2.id.fastscroll) - RecyclerFastScroller mFastScroll; @BindView(R2.id.swipe) SwipeRefreshLayout mSwipe; @BindView(R2.id.search_result) @@ -89,15 +86,13 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true); ViewCompat.setNestedScrollingEnabled(mRecyclerView, false); - ViewHelper.resetNavigationBarBottomPadding(getActivity(), mRecyclerView, - getActivity().getResources().getConfiguration().orientation); + ViewHelper.resetViewBottomPadding(mRecyclerView, false); mSwipe.setEnabled(false); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), - getActivity().getResources().getInteger(R.integer.column_num))); + getActivity().getResources().getInteger(R.integer.wallpapers_column_count))); mRecyclerView.setHasFixedSize(false); - mFastScroll.attachRecyclerView(mRecyclerView); getWallpapers(); } @@ -107,7 +102,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.menu_wallpaper_search, menu); MenuItem search = menu.findItem(R.id.menu_search); - int color = ColorHelper.getAttributeColor(getActivity(), R.attr.search_toolbar_icon); + int color = ColorHelper.getAttributeColor(getActivity(), R.attr.toolbar_icon); search.setIcon(DrawableHelper.getTintedDrawable(getActivity(), R.drawable.ic_toolbar_search, color)); @@ -121,7 +116,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { mSearchView.clearFocus(); ViewHelper.changeSearchViewTextColor(mSearchView, color, - ColorHelper.getAttributeColor(getActivity(), R.attr.search_toolbar_hint)); + ColorHelper.setColorAlpha(color, 0.6f)); View view = mSearchView.findViewById(android.support.v7.appcompat.R.id.search_plate); if (view != null) view.setBackgroundColor(Color.TRANSPARENT); @@ -153,7 +148,7 @@ public boolean onQueryTextSubmit(String string) { public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); ViewHelper.resetSpanCount(getActivity(), mRecyclerView); - ViewHelper.resetNavigationBarBottomPadding(getActivity(), mRecyclerView, newConfig.orientation); + ViewHelper.resetViewBottomPadding(mRecyclerView, false); } @Override @@ -163,7 +158,7 @@ public void onDestroy() { } @Override - public void OnWallpaperSelected(int position) { + public void onWallpaperSelected(int position) { if (mAdapter == null) return; if (position < 0 || position > mAdapter.getItemCount()) return; @@ -181,7 +176,7 @@ private void filterSearch(String query) { } else mSearchResult.setVisibility(View.GONE); } catch (Exception e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); } } @@ -205,7 +200,7 @@ protected Boolean doInBackground(Void... voids) { wallpapers = database.getFilteredWallpapers(); return true; } catch (Exception e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); return false; } } diff --git a/library/src/main/java/com/dm/wallpaper/board/fragments/WallpapersFragment.java b/library/src/main/java/com/dm/wallpaper/board/fragments/WallpapersFragment.java index 561204e0..ee60173a 100644 --- a/library/src/main/java/com/dm/wallpaper/board/fragments/WallpapersFragment.java +++ b/library/src/main/java/com/dm/wallpaper/board/fragments/WallpapersFragment.java @@ -11,7 +11,6 @@ import android.support.v4.app.FragmentTransaction; import android.support.v4.content.ContextCompat; import android.support.v4.view.MenuItemCompat; -import android.support.v4.view.ViewCompat; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.GridLayoutManager; @@ -41,10 +40,10 @@ import com.dm.wallpaper.board.utils.Animator; import com.dm.wallpaper.board.utils.Extras; import com.dm.wallpaper.board.utils.ListUtils; +import com.dm.wallpaper.board.utils.LogUtil; import com.dm.wallpaper.board.utils.listeners.SearchListener; import com.dm.wallpaper.board.utils.listeners.WallpaperBoardListener; import com.dm.wallpaper.board.utils.listeners.WallpaperListener; -import com.pluscubed.recyclerfastscroll.RecyclerFastScroller; import com.rafakob.drawme.DrawMeButton; import java.io.InputStream; @@ -78,8 +77,6 @@ public class WallpapersFragment extends Fragment implements WallpaperListener { @BindView(R2.id.recyclerview) RecyclerView mRecyclerView; - @BindView(R2.id.fastscroll) - RecyclerFastScroller mFastScroll; @BindView(R2.id.swipe) SwipeRefreshLayout mSwipe; @BindView(R2.id.progress) @@ -99,18 +96,15 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - ViewCompat.setNestedScrollingEnabled(mRecyclerView, false); - ViewHelper.resetNavigationBarBottomPadding(getActivity(), mRecyclerView, - getActivity().getResources().getConfiguration().orientation); + ViewHelper.resetViewBottomPadding(mRecyclerView, true); mProgress.getIndeterminateDrawable().setColorFilter(ColorHelper.getAttributeColor( getActivity(), R.attr.colorAccent), PorterDuff.Mode.SRC_IN); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), - getActivity().getResources().getInteger(R.integer.column_num))); + getActivity().getResources().getInteger(R.integer.wallpapers_column_count))); mRecyclerView.setHasFixedSize(false); - mFastScroll.attachRecyclerView(mRecyclerView); mSwipe.setColorSchemeColors(ColorHelper.getAttributeColor( getActivity(), R.attr.colorAccent)); @@ -129,7 +123,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); ViewHelper.resetSpanCount(getActivity(), mRecyclerView); - ViewHelper.resetNavigationBarBottomPadding(getActivity(), mRecyclerView, newConfig.orientation); + ViewHelper.resetViewBottomPadding(mRecyclerView, true); } @Override @@ -146,7 +140,7 @@ public boolean onMenuItemActionExpand(MenuItem item) { setHasOptionsMenu(false); SearchListener listener = (SearchListener) getActivity(); - listener.OnSearchExpanded(true); + listener.onSearchExpanded(true); FragmentTransaction ft = fm.beginTransaction() .replace(R.id.container, new WallpaperSearchFragment(), @@ -184,7 +178,7 @@ public void onDestroy() { } @Override - public void OnWallpaperSelected(int position) { + public void onWallpaperSelected(int position) { if (mAdapter == null) return; if (position < 0 || position > mAdapter.getItemCount()) return; @@ -204,7 +198,7 @@ public void initPopupBubble() { Animator.startAlphaAnimation(getActivity().findViewById(R.id.popup_bubble), 200, View.GONE); getWallpapers(true); }); - Animator.startSlideDownAnimation(getActivity(), popupBubble, null); + Animator.startSlideDownAnimation(popupBubble, View.VISIBLE); } } @@ -297,7 +291,7 @@ protected Boolean doInBackground(Void... voids) { } return false; } catch (Exception e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); return false; } } @@ -315,7 +309,7 @@ protected void onPostExecute(Boolean aBoolean) { mRecyclerView.setAdapter(mAdapter); WallpaperBoardListener listener = (WallpaperBoardListener) getActivity(); - listener.OnWallpapersChecked(new Intent().putExtra(Extras.EXTRA_SIZE, + listener.onWallpapersChecked(new Intent().putExtra(Extras.EXTRA_SIZE, Preferences.getPreferences(getActivity()).getAvailableWallpapersCount())); } else { Toast.makeText(getActivity(), R.string.connection_failed, Toast.LENGTH_LONG).show(); diff --git a/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/CreditsFragment.java b/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/CreditsFragment.java index 720d3a09..5722fb42 100644 --- a/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/CreditsFragment.java +++ b/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/CreditsFragment.java @@ -18,6 +18,8 @@ import com.dm.wallpaper.board.adapters.CreditsAdapter; import com.dm.wallpaper.board.items.Credit; import com.dm.wallpaper.board.utils.Extras; +import com.dm.wallpaper.board.utils.LogUtil; + import org.xmlpull.v1.XmlPullParser; import java.util.ArrayList; @@ -46,6 +48,13 @@ public class CreditsFragment extends DialogFragment { + @BindView(R2.id.listview) + ListView mListView; + + private int mType; + + private AsyncTask mGetCredits; + private static final String TAG = "com.field.guide.dialog.credits"; private static CreditsFragment newInstance(int type) { @@ -69,13 +78,6 @@ public static void showCreditsDialog(FragmentManager fm, int type) { } catch (IllegalStateException | IllegalArgumentException ignored) {} } - @BindView(R2.id.listview) - ListView mListView; - - private int mType; - - private AsyncTask mGetCredits; - @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -163,7 +165,7 @@ protected Boolean doInBackground(Void... voids) { } return true; } catch (Exception e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); return false; } } @@ -182,5 +184,4 @@ protected void onPostExecute(Boolean aBoolean) { } }.execute(); } - } diff --git a/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/FilterFragment.java b/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/FilterFragment.java index 9a4b8271..4fdc0b0f 100644 --- a/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/FilterFragment.java +++ b/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/FilterFragment.java @@ -45,6 +45,9 @@ public class FilterFragment extends DialogFragment { + @BindView(R2.id.listview) + ListView listView; + private boolean mIsMuzei; private static final String MUZEI = "muzei"; @@ -71,9 +74,6 @@ public static void showFilterDialog(FragmentManager fm, boolean isMuzei) { } catch (IllegalArgumentException | IllegalStateException ignored) {} } - @BindView(R2.id.listview) - ListView listView; - @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { @@ -102,6 +102,8 @@ public void onActivityCreated(Bundle savedInstanceState) { @Override public void onDismiss(DialogInterface dialog) { + if (getActivity() == null) return; + FragmentManager fm = getActivity().getSupportFragmentManager(); if (fm == null) return; diff --git a/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/InAppBillingFragment.java b/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/InAppBillingFragment.java index c234116e..a02d8225 100644 --- a/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/InAppBillingFragment.java +++ b/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/InAppBillingFragment.java @@ -20,11 +20,16 @@ import com.anjlab.android.iab.v3.BillingProcessor; import com.anjlab.android.iab.v3.SkuDetails; import com.dm.wallpaper.board.R; +import com.dm.wallpaper.board.R2; import com.dm.wallpaper.board.adapters.InAppBillingAdapter; import com.dm.wallpaper.board.items.InAppBilling; import com.dm.wallpaper.board.utils.Extras; +import com.dm.wallpaper.board.utils.LogUtil; import com.dm.wallpaper.board.utils.listeners.InAppBillingListener; +import butterknife.BindView; +import butterknife.ButterKnife; + /* * Wallpaper Board * @@ -45,6 +50,17 @@ public class InAppBillingFragment extends DialogFragment { + @BindView(R2.id.inapp_list) + ListView mListView; + @BindView(R2.id.progress) + ProgressBar mProgress; + + private String mKey; + private String[] mProductsId; + + private InAppBillingAdapter mAdapter; + private AsyncTask mLoadInAppProducts; + private static BillingProcessor mBillingProcessor; private static final String TAG = "com.dm.wallpaper.board.dialog.inappbilling"; @@ -73,15 +89,6 @@ public static void showInAppBillingDialog(@NonNull FragmentManager fm, BillingPr } catch (IllegalArgumentException | IllegalStateException ignored) {} } - private ListView mInAppList; - private ProgressBar mProgress; - - private String mKey; - private String[] mProductsId; - - private InAppBillingAdapter mAdapter; - private AsyncTask mLoadInAppProducts; - @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -101,7 +108,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { if (mLoadInAppProducts == null) { try { InAppBillingListener listener = (InAppBillingListener) getActivity(); - listener.OnInAppBillingSelected(mAdapter.getSelectedProduct()); + listener.onInAppBillingSelected(mAdapter.getSelectedProduct()); } catch (Exception ignored) {} dismiss(); } @@ -112,8 +119,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { dialog.show(); setCancelable(false); - mInAppList = (ListView) dialog.findViewById(R.id.inapp_list); - mProgress = (ProgressBar) dialog.findViewById(R.id.progress); + ButterKnife.bind(this, dialog); return dialog; } @@ -179,7 +185,7 @@ protected Boolean doInBackground(Void... voids) { } return true; } catch (Exception e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); return false; } } @@ -192,7 +198,7 @@ protected void onPostExecute(Boolean aBoolean) { mProgress.setVisibility(View.GONE); if (aBoolean) { mAdapter = new InAppBillingAdapter(getActivity(), inAppBillings); - mInAppList.setAdapter(mAdapter); + mListView.setAdapter(mAdapter); } else { dismiss(); if (!isBillingNotReady) @@ -204,5 +210,4 @@ protected void onPostExecute(Boolean aBoolean) { }.execute(); } - } diff --git a/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/LicensesFragment.java b/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/LicensesFragment.java index 8700b5db..e05c35e2 100644 --- a/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/LicensesFragment.java +++ b/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/LicensesFragment.java @@ -15,12 +15,14 @@ import com.afollestad.materialdialogs.MaterialDialog; import com.dm.wallpaper.board.R; -import com.dm.wallpaper.board.utils.Extras; +import com.dm.wallpaper.board.R2; +import com.dm.wallpaper.board.utils.LogUtil; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; +import butterknife.BindView; import butterknife.ButterKnife; /* @@ -43,6 +45,11 @@ public class LicensesFragment extends DialogFragment { + @BindView(R2.id.webview) + WebView mWebView; + + private AsyncTask mLoadLicenses; + private static final String TAG = "com.dm.wallpaper.board.dialog.licenses"; private static LicensesFragment newInstance() { @@ -62,10 +69,6 @@ public static void showLicensesDialog(FragmentManager fm) { } catch (IllegalStateException | IllegalArgumentException ignored) {} } - private WebView mWebView; - - private AsyncTask mLoadLicenses; - @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { @@ -75,7 +78,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { MaterialDialog dialog = builder.build(); dialog.show(); - mWebView = ButterKnife.findById(dialog, R.id.webview); + ButterKnife.bind(this, dialog); return dialog; } @@ -120,7 +123,7 @@ protected Boolean doInBackground(Void... voids) { bufferedReader.close(); return true; } catch (Exception e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); return false; } } @@ -140,7 +143,6 @@ protected void onPostExecute(Boolean aBoolean) { }.execute(); } - } diff --git a/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/RefreshDurationFragment.java b/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/RefreshDurationFragment.java index 93213374..402a7fda 100644 --- a/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/RefreshDurationFragment.java +++ b/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/RefreshDurationFragment.java @@ -19,7 +19,7 @@ import com.dm.wallpaper.board.R2; import com.dm.wallpaper.board.helpers.ColorHelper; import com.dm.wallpaper.board.helpers.DrawableHelper; -import com.dm.wallpaper.board.utils.Extras; +import com.dm.wallpaper.board.utils.LogUtil; import com.dm.wallpaper.board.utils.listeners.RefreshDurationListener; import butterknife.BindView; @@ -45,6 +45,16 @@ public class RefreshDurationFragment extends DialogFragment implements View.OnClickListener { + @BindView(R2.id.number_picker) + NumberPicker mNumberPicker; + @BindView(R2.id.minute) + AppCompatRadioButton mMinute; + @BindView(R2.id.hour) + AppCompatRadioButton mHour; + + private int mRotateTime; + private boolean mIsMinute; + private static final String MINUTE = "minute"; private static final String ROTATE_TIME = "rotate_time"; private static final String TAG = "com.dm.wallpaper.board.dialog.refresh.duration"; @@ -71,16 +81,6 @@ public static void showRefreshDurationDialog(FragmentManager fm, int rotateTime, } catch (IllegalStateException | IllegalArgumentException ignored) {} } - @BindView(R2.id.number_picker) - NumberPicker mNumberPicker; - @BindView(R2.id.minute) - AppCompatRadioButton mMinute; - @BindView(R2.id.hour) - AppCompatRadioButton mHour; - - private int mRotateTime; - private boolean mIsMinute; - @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { @@ -120,7 +120,7 @@ public void onActivityCreated(Bundle savedInstanceState) { @Override public void onDismiss(DialogInterface dialog) { RefreshDurationListener listener = (RefreshDurationListener) getActivity(); - listener.OnRefreshDurationSet(mNumberPicker.getValue(), mMinute.isChecked()); + listener.onRefreshDurationSet(mNumberPicker.getValue(), mMinute.isChecked()); super.onDismiss(dialog); } @@ -146,7 +146,7 @@ private void setDividerColor (NumberPicker picker) { pf.set(picker, DrawableHelper.getTintedDrawable( getActivity(), R.drawable.numberpicker_divider, color)); } catch (Exception e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); } break; } diff --git a/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/WallpaperOptionsFragment.java b/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/WallpaperOptionsFragment.java index bba8588a..b311898f 100644 --- a/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/WallpaperOptionsFragment.java +++ b/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/WallpaperOptionsFragment.java @@ -16,7 +16,9 @@ import com.afollestad.materialdialogs.MaterialDialog; import com.danimahardhika.cafebar.CafeBar; +import com.danimahardhika.cafebar.CafeBarTheme; import com.dm.wallpaper.board.R; +import com.dm.wallpaper.board.R2; import com.dm.wallpaper.board.helpers.ColorHelper; import com.dm.wallpaper.board.helpers.DrawableHelper; import com.dm.wallpaper.board.helpers.FileHelper; @@ -26,6 +28,9 @@ import java.io.File; +import butterknife.BindView; +import butterknife.ButterKnife; + /* * Wallpaper Board * @@ -46,6 +51,18 @@ public class WallpaperOptionsFragment extends DialogFragment implements View.OnClickListener { + @BindView(R2.id.apply) + LinearLayout mApply; + @BindView(R2.id.save) + LinearLayout mSave; + @BindView(R2.id.apply_icon) + ImageView mApplyIcon; + @BindView(R2.id.save_icon) + ImageView mSaveIcon; + + private String mName; + private String mUrl; + private static final String TAG = "com.dm.wallpaper.board.dialog.wallpaper.options"; private static WallpaperOptionsFragment newInstance(String url, String name) { @@ -70,14 +87,6 @@ public static void showWallpaperOptionsDialog(FragmentManager fm, String url, St } catch (IllegalArgumentException | IllegalStateException ignored) {} } - private LinearLayout mApply; - private LinearLayout mSave; - private ImageView mApplyIcon; - private ImageView mSaveIcon; - - private String mName; - private String mUrl; - @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { @@ -86,10 +95,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { MaterialDialog dialog = builder.build(); dialog.show(); - mApply = (LinearLayout) dialog.findViewById(R.id.apply); - mSave = (LinearLayout) dialog.findViewById(R.id.save); - mApplyIcon = (ImageView) dialog.findViewById(R.id.apply_icon); - mSaveIcon = (ImageView) dialog.findViewById(R.id.save_icon); + ButterKnife.bind(this, dialog); return dialog; } @@ -144,10 +150,9 @@ public void onClick(View view) { if (target.exists()) { Context context = getActivity(); CafeBar.builder(getActivity()) + .theme(new CafeBarTheme.Custom(ColorHelper.getAttributeColor(getActivity(), R.attr.card_background))) .autoDismiss(false) - .swipeToDismiss(false) - .floating(true) - .fitSystemWindow(true) + .fitSystemWindow(R.bool.view_fitsystemwindow) .maxLines(4) .content(String.format(getResources().getString(R.string.wallpaper_download_exist), ("\"" +mName + FileHelper.IMAGE_EXTENSION+ "\""))) diff --git a/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/WallpaperSettingsFragment.java b/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/WallpaperSettingsFragment.java index 91051923..7ab6466e 100644 --- a/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/WallpaperSettingsFragment.java +++ b/library/src/main/java/com/dm/wallpaper/board/fragments/dialogs/WallpaperSettingsFragment.java @@ -15,8 +15,12 @@ import com.afollestad.materialdialogs.MaterialDialog; import com.dm.wallpaper.board.R; +import com.dm.wallpaper.board.R2; import com.dm.wallpaper.board.preferences.Preferences; +import butterknife.BindView; +import butterknife.ButterKnife; + /* * Wallpaper Board * @@ -37,8 +41,18 @@ public class WallpaperSettingsFragment extends DialogFragment implements View.OnClickListener { + @BindView(R2.id.enable_scroll_radio) + AppCompatRadioButton mEnableScrollRadio; + @BindView(R2.id.disable_scroll_radio) + AppCompatRadioButton mDisableScrollRadio; + @BindView(R2.id.enable_scroll) + LinearLayout mEnableScroll; + @BindView(R2.id.disable_scroll) + LinearLayout mDisableScroll; + private static final String TAG = "com.dm.wallpaper.board.dialog.wallpaper.settings"; + @NonNull private static WallpaperSettingsFragment newInstance() { return new WallpaperSettingsFragment(); } @@ -56,11 +70,6 @@ public static void showWallpaperSettings(FragmentManager fm) { } catch (IllegalStateException | IllegalArgumentException ignored) {} } - private AppCompatRadioButton mEnableScrollRadio; - private AppCompatRadioButton mDisableScrollRadio; - private LinearLayout mEnableScroll; - private LinearLayout mDisableScroll; - @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { @@ -71,10 +80,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { MaterialDialog dialog = builder.build(); dialog.show(); - mEnableScrollRadio = (AppCompatRadioButton) dialog.findViewById(R.id.enable_scroll_radio); - mDisableScrollRadio = (AppCompatRadioButton) dialog.findViewById(R.id.disable_scroll_radio); - mEnableScroll = (LinearLayout) dialog.findViewById(R.id.enable_scroll); - mDisableScroll = (LinearLayout) dialog.findViewById(R.id.disable_scroll); + ButterKnife.bind(this, dialog); return dialog; } @@ -108,5 +114,4 @@ private void toggleRadio() { mEnableScrollRadio.setChecked(scroll); mDisableScrollRadio.setChecked(!scroll); } - } diff --git a/library/src/main/java/com/dm/wallpaper/board/helpers/ColorHelper.java b/library/src/main/java/com/dm/wallpaper/board/helpers/ColorHelper.java index 4f4363d4..81775ddc 100644 --- a/library/src/main/java/com/dm/wallpaper/board/helpers/ColorHelper.java +++ b/library/src/main/java/com/dm/wallpaper/board/helpers/ColorHelper.java @@ -84,20 +84,20 @@ public static int setColorAlpha(@ColorInt int color, float alpha) { return Color.argb(alpha2, red, green, blue); } - public static ColorStateList getColorStateList(int attr, @ColorInt int color, @ColorInt int color2) { + public static ColorStateList getColorStateList(@ColorInt int color) { int[][] states = new int[][] { - new int[] {attr}, + new int[] {android.R.attr.state_pressed}, new int[] {} }; int[] colors = new int[] { - color, - color2 + ColorHelper.getDarkerColor(color, 0.9f), + color }; return new ColorStateList(states, colors); } private static boolean isLightToolbar(@NonNull Context context) { - int color = getAttributeColor(context, R.attr.toolbar_color); + int color = getAttributeColor(context, R.attr.colorPrimary); int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); diff --git a/library/src/main/java/com/dm/wallpaper/board/helpers/ContextHelper.java b/library/src/main/java/com/dm/wallpaper/board/helpers/ContextHelper.java new file mode 100644 index 00000000..2ff8fb82 --- /dev/null +++ b/library/src/main/java/com/dm/wallpaper/board/helpers/ContextHelper.java @@ -0,0 +1,36 @@ +package com.dm.wallpaper.board.helpers; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.v7.view.ContextThemeWrapper; +import android.view.View; + +/* + * Wallpaper Board + * + * Copyright (c) 2017 Dani Mahardhika + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class ContextHelper { + + @NonNull + public static Context getBaseContext(@NonNull View view) { + Context context = view.getContext(); + if (context instanceof ContextThemeWrapper) { + context = ((ContextThemeWrapper) view.getContext()).getBaseContext(); + } + return context; + } +} diff --git a/library/src/main/java/com/dm/wallpaper/board/helpers/CrashReportHelper.java b/library/src/main/java/com/dm/wallpaper/board/helpers/CrashReportHelper.java index 940c13ec..6a1578fc 100644 --- a/library/src/main/java/com/dm/wallpaper/board/helpers/CrashReportHelper.java +++ b/library/src/main/java/com/dm/wallpaper/board/helpers/CrashReportHelper.java @@ -10,7 +10,7 @@ import com.dm.wallpaper.board.BuildConfig; import com.dm.wallpaper.board.R; -import com.dm.wallpaper.board.utils.Extras; +import com.dm.wallpaper.board.utils.LogUtil; import java.io.BufferedWriter; import java.io.File; @@ -53,7 +53,7 @@ public static String buildCrashLog(@NonNull Context context, @NonNull File folde return fileDir.toString(); } catch (Exception | OutOfMemoryError e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); } return null; } @@ -88,5 +88,4 @@ public static String getDeviceInfoForCrashReport(@NonNull Context context) { "\nApp Name : " +context.getResources().getString(R.string.app_name) + "\n"+ getDeviceInfo(context); } - } diff --git a/library/src/main/java/com/dm/wallpaper/board/helpers/DrawableHelper.java b/library/src/main/java/com/dm/wallpaper/board/helpers/DrawableHelper.java index 827d7295..ef2f1df4 100644 --- a/library/src/main/java/com/dm/wallpaper/board/helpers/DrawableHelper.java +++ b/library/src/main/java/com/dm/wallpaper/board/helpers/DrawableHelper.java @@ -86,5 +86,4 @@ public static Drawable getTintedDrawable(@NonNull Context context, @DrawableRes return null; } } - } diff --git a/library/src/main/java/com/dm/wallpaper/board/helpers/FileHelper.java b/library/src/main/java/com/dm/wallpaper/board/helpers/FileHelper.java index 9bc5085d..69fa0121 100644 --- a/library/src/main/java/com/dm/wallpaper/board/helpers/FileHelper.java +++ b/library/src/main/java/com/dm/wallpaper/board/helpers/FileHelper.java @@ -7,7 +7,8 @@ import android.support.v4.content.FileProvider; import android.util.Log; -import com.dm.wallpaper.board.utils.Extras; +import com.dm.wallpaper.board.utils.LogUtil; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -35,6 +36,31 @@ public class FileHelper { public static final String IMAGE_EXTENSION = ".jpeg"; + public static final int MB = (1024 * 1014); + public static final int KB = 1024; + + public static long getCacheSize(@NonNull File dir) { + if (dir.exists()) { + long result = 0; + File[] fileList = dir.listFiles(); + for (File aFileList : fileList) { + if (aFileList.isDirectory()) { + result += getCacheSize(aFileList); + } else { + result += aFileList.length(); + } + } + return result; + } + return 0; + } + + public static void clearCache(@NonNull File cache) { + if (cache.isDirectory()) + for (File child : cache.listFiles()) + clearCache(child); + cache.delete(); + } static boolean copyFile(@NonNull File file, @NonNull File target) { try { @@ -56,7 +82,7 @@ static boolean copyFile(@NonNull File file, @NonNull File target) { outputStream.close(); return true; } catch (Exception e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); } return false; } @@ -66,7 +92,7 @@ public static Uri getUriFromFile(Context context, String applicationId, File fil try { return FileProvider.getUriForFile(context, applicationId + ".fileProvider", file); } catch (IllegalArgumentException e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); } return null; } diff --git a/library/src/main/java/com/dm/wallpaper/board/helpers/InAppBillingHelper.java b/library/src/main/java/com/dm/wallpaper/board/helpers/InAppBillingHelper.java index 8d2a7e1e..27d29b53 100644 --- a/library/src/main/java/com/dm/wallpaper/board/helpers/InAppBillingHelper.java +++ b/library/src/main/java/com/dm/wallpaper/board/helpers/InAppBillingHelper.java @@ -37,7 +37,7 @@ public InAppBillingHelper(@NonNull Context context) { @Override public void onProductPurchased(String productId, TransactionDetails details) { InAppBillingListener listener = (InAppBillingListener) mContext; - listener.OnInAppBillingConsume(productId); + listener.onInAppBillingConsume(productId); } @Override @@ -49,13 +49,13 @@ public void onPurchaseHistoryRestored() { public void onBillingError(int errorCode, Throwable error) { if (errorCode == Constants.BILLING_ERROR_FAILED_TO_INITIALIZE_PURCHASE) { InAppBillingListener listener = (InAppBillingListener) mContext; - listener.OnInAppBillingInitialized(false); + listener.onInAppBillingInitialized(false); } } @Override public void onBillingInitialized() { InAppBillingListener listener = (InAppBillingListener) mContext; - listener.OnInAppBillingInitialized(true); + listener.onInAppBillingInitialized(true); } } diff --git a/library/src/main/java/com/dm/wallpaper/board/helpers/LicenseHelper.java b/library/src/main/java/com/dm/wallpaper/board/helpers/LicenseHelper.java index 44e21f25..d77bc74f 100644 --- a/library/src/main/java/com/dm/wallpaper/board/helpers/LicenseHelper.java +++ b/library/src/main/java/com/dm/wallpaper/board/helpers/LicenseHelper.java @@ -5,13 +5,12 @@ import android.provider.Settings.Secure; import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; -import android.util.Log; import android.widget.Toast; import com.afollestad.materialdialogs.MaterialDialog; import com.dm.wallpaper.board.R; import com.dm.wallpaper.board.preferences.Preferences; -import com.dm.wallpaper.board.utils.Extras; +import com.dm.wallpaper.board.utils.LogUtil; import com.google.android.vending.licensing.AESObfuscator; import com.google.android.vending.licensing.LicenseChecker; import com.google.android.vending.licensing.LicenseCheckerCallback; @@ -41,6 +40,7 @@ public class LicenseHelper implements LicenseCheckerCallback { private final Context mContext; private MaterialDialog mDialog; + @NonNull public static LicenseHelper getLicenseChecker(@NonNull Context context) { return new LicenseHelper(context); } @@ -61,7 +61,7 @@ public void checkLicense(String licenseKey, byte[] salt) { checker.checkAccess(this); getDialog().show(); } else { - Log.d(Extras.LOG_TAG, "Unable to check license, random bytes is wrong!"); + LogUtil.e("Unable to check license, random bytes is wrong!"); } } @@ -124,7 +124,7 @@ private void showLicenseDialog(int reason) { .content(message) .positiveText(R.string.close) .onPositive((dialog, which) -> { - OnLicenseChecked(reason); + onLicenseChecked(reason); dialog.dismiss(); }) .cancelable(false) @@ -143,7 +143,7 @@ private void showRetryDialog() { .show(); } - private void OnLicenseChecked(int reason) { + private void onLicenseChecked(int reason) { Preferences.getPreferences(mContext).setFirstRun(false); if (reason == Policy.LICENSED) { Preferences.getPreferences(mContext).setLicensed(true); diff --git a/library/src/main/java/com/dm/wallpaper/board/helpers/MuzeiHelper.java b/library/src/main/java/com/dm/wallpaper/board/helpers/MuzeiHelper.java index 2f3f9a39..68b18214 100644 --- a/library/src/main/java/com/dm/wallpaper/board/helpers/MuzeiHelper.java +++ b/library/src/main/java/com/dm/wallpaper/board/helpers/MuzeiHelper.java @@ -76,5 +76,4 @@ private int getRandomInt(int size) { return 0; } } - } diff --git a/library/src/main/java/com/dm/wallpaper/board/helpers/PermissionHelper.java b/library/src/main/java/com/dm/wallpaper/board/helpers/PermissionHelper.java index 112dfddb..694de3b7 100644 --- a/library/src/main/java/com/dm/wallpaper/board/helpers/PermissionHelper.java +++ b/library/src/main/java/com/dm/wallpaper/board/helpers/PermissionHelper.java @@ -56,5 +56,4 @@ public static void requestStoragePermission(@NonNull Context context) { public static void showPermissionStorageDenied(@NonNull Context context) { Toast.makeText(context, R.string.permission_storage_denied, Toast.LENGTH_LONG).show(); } - } diff --git a/library/src/main/java/com/dm/wallpaper/board/helpers/SoftKeyboardHelper.java b/library/src/main/java/com/dm/wallpaper/board/helpers/SoftKeyboardHelper.java index 6b52225e..a8db63a6 100644 --- a/library/src/main/java/com/dm/wallpaper/board/helpers/SoftKeyboardHelper.java +++ b/library/src/main/java/com/dm/wallpaper/board/helpers/SoftKeyboardHelper.java @@ -47,7 +47,7 @@ public static void openKeyboard(@NonNull Context context) { } } -/* + /* * This code was taken from https://github.com/mikepenz/MaterialDrawer/issues/95#issuecomment-80519589 */ diff --git a/library/src/main/java/com/dm/wallpaper/board/helpers/ViewHelper.java b/library/src/main/java/com/dm/wallpaper/board/helpers/ViewHelper.java index c071af8b..d0df9f61 100644 --- a/library/src/main/java/com/dm/wallpaper/board/helpers/ViewHelper.java +++ b/library/src/main/java/com/dm/wallpaper/board/helpers/ViewHelper.java @@ -4,23 +4,20 @@ import android.content.Context; import android.content.res.Configuration; import android.content.res.Resources; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Point; -import android.graphics.drawable.ColorDrawable; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.TransitionDrawable; import android.os.Build; -import android.support.annotation.AttrRes; +import android.support.annotation.IntegerRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.design.widget.AppBarLayout; -import android.support.design.widget.CollapsingToolbarLayout; import android.support.design.widget.CoordinatorLayout; -import android.support.v4.view.ViewCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.StaggeredGridLayoutManager; +import android.support.v7.widget.Toolbar; import android.util.Log; import android.util.TypedValue; import android.view.Display; @@ -32,7 +29,7 @@ import android.widget.TextView; import com.dm.wallpaper.board.R; -import com.dm.wallpaper.board.utils.Extras; +import com.dm.wallpaper.board.utils.LogUtil; import com.nostra13.universalimageloader.core.ImageLoader; /* @@ -55,13 +52,56 @@ public class ViewHelper { + public static void setupToolbar(@NonNull Toolbar toolbar, boolean adjustHeight) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Context context = ContextHelper.getBaseContext(toolbar); + int statusBarSize = ViewHelper.getStatusBarHeight(context); + toolbar.setPadding( + toolbar.getPaddingLeft(), + toolbar.getPaddingTop() + statusBarSize, + toolbar.getPaddingRight(), + toolbar.getPaddingBottom() + ); + + if (adjustHeight) { + toolbar.getLayoutParams().height = getToolbarHeight(context) + statusBarSize; + } + } + } + + public static int getToolbarHeight(@NonNull Context context) { + TypedValue typedValue = new TypedValue(); + int[] actionBarSize = new int[] { R.attr.actionBarSize }; + int indexOfAttrTextSize = 0; + TypedArray a = context.obtainStyledAttributes(typedValue.data, actionBarSize); + int size = a.getDimensionPixelSize(indexOfAttrTextSize, -1); + a.recycle(); + return size; + } + public static void resetSpanCount(@NonNull Context context, @NonNull RecyclerView recyclerView) { try { GridLayoutManager manager = (GridLayoutManager) recyclerView.getLayoutManager(); - manager.setSpanCount(context.getResources().getInteger(R.integer.column_num)); + manager.setSpanCount(context.getResources().getInteger(R.integer.wallpapers_column_count)); manager.requestLayout(); } catch (Exception e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); + } + } + + public static void resetSpanCount(@NonNull Context context, @NonNull RecyclerView recyclerView, @IntegerRes int res) { + try { + if (recyclerView.getLayoutManager() instanceof GridLayoutManager) { + GridLayoutManager manager = (GridLayoutManager) recyclerView.getLayoutManager(); + manager.setSpanCount(context.getResources().getInteger(res)); + manager.requestLayout(); + } else if (recyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) { + StaggeredGridLayoutManager manager = (StaggeredGridLayoutManager) recyclerView.getLayoutManager(); + manager.setSpanCount(context.getResources().getInteger(res)); + manager.requestLayout(); + } + } catch (Exception e) { + LogUtil.e(Log.getStackTraceString(e)); } } @@ -87,45 +127,73 @@ public static void disableTranslucentNavigationBar(@NonNull Context context) { } } - public static void resetNavigationBarBottomPadding(@NonNull Context context, @Nullable View view, - int orientation) { + public static void resetViewBottomPadding(@Nullable View view, boolean scroll) { + if (view == null) return; + + Context context = ContextHelper.getBaseContext(view); + int orientation = context.getResources().getConfiguration().orientation; + + int left = view.getPaddingLeft(); + int right = view.getPaddingRight(); + int bottom = view.getPaddingBottom(); + int top = view.getPaddingTop(); + int navBar = 0; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - if (view != null) { - int left = view.getPaddingLeft(); - int right = view.getPaddingRight(); - int bottom = view.getPaddingBottom(); - int top = view.getPaddingTop(); - int navBar = getNavigationBarHeight(context); - - if (bottom > navBar) bottom -= navBar; - boolean tabletMode = context.getResources().getBoolean(R.bool.tablet_mode); - - if (tabletMode || orientation == Configuration.ORIENTATION_PORTRAIT) { - view.setPadding(left, top, right, (bottom + navBar)); - return; - } + boolean tabletMode = context.getResources().getBoolean(R.bool.tablet_mode); + if (tabletMode || orientation == Configuration.ORIENTATION_PORTRAIT) { + navBar = getNavigationBarHeight(context); + } - view.setPadding(left, top, right, bottom); + if (!scroll) { + navBar += ViewHelper.getStatusBarHeight(context); } } + + if (bottom > navBar) bottom -= getNavigationBarHeight(context); + if (!scroll) { + navBar += ViewHelper.getToolbarHeight(context); + } + view.setPadding(left, top, right, (bottom + navBar)); } - public static void disableAppBarDrag(@Nullable AppBarLayout appBar) { - if (appBar != null) { - if (ViewCompat.isLaidOut(appBar)) { - CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) - appBar.getLayoutParams(); - AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior(); - if (behavior != null) { - behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() { - @Override - public boolean canDrag(@NonNull AppBarLayout appBarLayout) { - return false; - } - }); - } + public static void resetViewBottomMargin(@Nullable View view) { + if (view == null) return; + + Context context = ContextHelper.getBaseContext(view); + int orientation = context.getResources().getConfiguration().orientation; + + if (!(view.getLayoutParams() instanceof CoordinatorLayout.LayoutParams)) + return; + + CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) view.getLayoutParams(); + int left = params.leftMargin; + int right = params.rightMargin; + int bottom = params.bottomMargin; + int top = params.topMargin; + int bottomNavBar = 0; + int rightNavBar = 0; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + boolean tabletMode = context.getResources().getBoolean(R.bool.tablet_mode); + if (tabletMode || orientation == Configuration.ORIENTATION_PORTRAIT) { + bottomNavBar = getNavigationBarHeight(context); + } else { + rightNavBar = getNavigationBarHeight(context); } } + + int navBar = getNavigationBarHeight(context); + if ((bottom > bottomNavBar) && ((bottom - navBar) > 0)) + bottom -= navBar; + if ((right > rightNavBar) && ((right - navBar) > 0)) + right -= navBar; + + params.setMargins(left, top, (right + rightNavBar), (bottom + bottomNavBar)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + params.setMarginEnd((right + rightNavBar)); + } + view.setLayoutParams(params); } public static int getStatusBarHeight(@NonNull Context context) { @@ -183,7 +251,7 @@ public static void setApplicationWindowColor(@NonNull Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); - theme.resolveAttribute(R.attr.toolbar_color, typedValue, true); + theme.resolveAttribute(R.attr.colorPrimary, typedValue, true); Bitmap bitmap = ImageLoader.getInstance().loadImageSync("drawable://" +DrawableHelper.getResourceId(context, "icon")); ((AppCompatActivity) context).setTaskDescription(new ActivityManager.TaskDescription ( @@ -224,21 +292,4 @@ 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); - } - } - } diff --git a/library/src/main/java/com/dm/wallpaper/board/helpers/WallpaperHelper.java b/library/src/main/java/com/dm/wallpaper/board/helpers/WallpaperHelper.java index 3b31f963..f1b99fd6 100644 --- a/library/src/main/java/com/dm/wallpaper/board/helpers/WallpaperHelper.java +++ b/library/src/main/java/com/dm/wallpaper/board/helpers/WallpaperHelper.java @@ -21,16 +21,19 @@ import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; +import android.view.Window; +import android.view.WindowManager; import android.widget.Toast; import com.afollestad.materialdialogs.MaterialDialog; import com.danimahardhika.cafebar.CafeBar; import com.danimahardhika.cafebar.CafeBarDuration; +import com.danimahardhika.cafebar.CafeBarTheme; import com.dm.wallpaper.board.R; import com.dm.wallpaper.board.activities.WallpaperBoardActivity; import com.dm.wallpaper.board.preferences.Preferences; -import com.dm.wallpaper.board.utils.Extras; import com.dm.wallpaper.board.utils.ImageConfig; +import com.dm.wallpaper.board.utils.LogUtil; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.assist.FailReason; import com.nostra13.universalimageloader.core.assist.ImageSize; @@ -181,7 +184,7 @@ protected Boolean doInBackground(Void... voids) { return true; } } catch (Exception e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); return false; } } @@ -217,9 +220,6 @@ protected void onPostExecute(Boolean aBoolean) { super.onPostExecute(aBoolean); dialog.dismiss(); if (aBoolean) { - if (Preferences.getPreferences(context).getWallsDirectory().length() == 0) - Preferences.getPreferences(context).setWallsDirectory(output.toString()); - context.sendBroadcast(new Intent( Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile( new File(file.toString())))); @@ -235,17 +235,19 @@ protected void onPostExecute(Boolean aBoolean) { }.execute(); } - private static void wallpaperSaved(@NonNull Context context, @ColorInt int color, @NonNull File file) { + private static void wallpaperSaved(@Nullable Context context, @ColorInt int color, @NonNull File file) { + if (context == null) return; + String downloaded = context.getResources().getString( R.string.wallpaper_downloaded); - View rootView = ((AppCompatActivity) context).getWindow().getDecorView().findViewById(R.id.rootview); + + if (Preferences.getPreferences(context).getWallsDirectory().length() == 0) + Preferences.getPreferences(context).setWallsDirectory(file.getParent()); CafeBar.Builder builder = new CafeBar.Builder(context); - builder.to(rootView) - .duration(CafeBarDuration.LONG.getDuration()) + builder.theme(new CafeBarTheme.Custom(ColorHelper.getAttributeColor(context, R.attr.card_background))) + .duration(CafeBarDuration.MEDIUM.getDuration()) .maxLines(4) - .floating(true) - .swipeToDismiss(false) .content(downloaded + " " + file.toString()) .icon(R.drawable.ic_toolbar_download) .neutralText(R.string.open) @@ -263,8 +265,15 @@ private static void wallpaperSaved(@NonNull Context context, @ColorInt int color cafeBar.dismiss(); }); - if (rootView == null) { + Window window = ((AppCompatActivity) context).getWindow(); + WindowManager.LayoutParams params = window.getAttributes(); + int flags = params.flags; + + if ((flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == + WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) { builder.fitSystemWindow(true); + } else { + builder.fitSystemWindow(R.bool.view_fitsystemwindow); } CafeBar cafeBar = builder.build(); @@ -332,13 +341,13 @@ public static void applyWallpaper(@NonNull Context context, @Nullable RectF rect String imageUri = getWallpaperUri(context, url, name + FileHelper.IMAGE_EXTENSION); ImageSize imageSize = getScaledSize(context, url); - loadBitmap(context, dialog, 1, imageUri, rectF, imageSize.getWidth(), imageSize.getHeight()); + loadBitmap(context, dialog, 1, imageUri, rectF, imageSize); } private static void loadBitmap(Context context, MaterialDialog dialog, int call, String imageUri, - RectF rectF, int width, int height) { + RectF rectF, ImageSize imageSize) { final AsyncTask setWallpaper = getWallpaperAsync( - context, dialog, rectF, width, height); + context, dialog, rectF); dialog.setOnDismissListener(dialogInterface -> { ImageLoader.getInstance().stop(); @@ -346,7 +355,7 @@ private static void loadBitmap(Context context, MaterialDialog dialog, int call, }); ImageLoader.getInstance().handleSlowNetwork(true); - ImageLoader.getInstance().loadImage(imageUri, new ImageSize(width, height), + ImageLoader.getInstance().loadImage(imageUri, imageSize, ImageConfig.getWallpaperOptions(), new ImageLoadingListener() { @Override @@ -362,11 +371,11 @@ public void onLoadingFailed(String imageUri, View view, FailReason failReason) { if (failReason.getType() == FailReason.FailType.OUT_OF_MEMORY) { if (call <= 5) { double scaleFactor = 1 - (0.1 * call); - int scaledWidth = Double.valueOf(width * scaleFactor).intValue(); - int scaledHeight = Double.valueOf(height * scaleFactor).intValue(); + int scaledWidth = Double.valueOf(imageSize.getWidth() * scaleFactor).intValue(); + int scaledHeight = Double.valueOf(imageSize.getHeight() * scaleFactor).intValue(); RectF scaledRecF = getScaledRectF(rectF, (float) scaleFactor); - loadBitmap(context, dialog, (call + 1), imageUri, scaledRecF, scaledWidth, scaledHeight); + loadBitmap(context, dialog, (call + 1), imageUri, scaledRecF, new ImageSize(scaledWidth, scaledHeight)); return; } } @@ -393,7 +402,7 @@ public void onLoadingCancelled(String imageUri, View view) { } private static AsyncTask getWallpaperAsync(@NonNull Context context, MaterialDialog dialog, - RectF rectF, int width, int height) { + RectF rectF) { return new AsyncTask() { @Override @@ -406,11 +415,21 @@ protected Boolean doInBackground(Bitmap... bitmaps) { Bitmap bitmap = bitmaps[0]; if (!Preferences.getPreferences(context).isScrollWallpaper() && rectF != null) { - bitmap = Bitmap.createBitmap(width, height, bitmaps[0].getConfig()); + Point point = ViewHelper.getRealScreenSize(context); + + int targetWidth = Double.valueOf( + ((double) bitmaps[0].getHeight() / (double) point.y) + * (double) point.x).intValue(); + + bitmap = Bitmap.createBitmap( + targetWidth, + bitmaps[0].getHeight(), + bitmaps[0].getConfig()); Paint paint = new Paint(); paint.setFilterBitmap(true); paint.setAntiAlias(true); paint.setDither(true); + Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(bitmaps[0], null, rectF, paint); } @@ -424,7 +443,7 @@ protected Boolean doInBackground(Bitmap... bitmaps) { } return false; } catch (Exception | OutOfMemoryError e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); return false; } } @@ -443,8 +462,12 @@ protected void onPostExecute(Boolean aBoolean) { super.onPostExecute(aBoolean); dialog.dismiss(); if (aBoolean) { - Toast.makeText(context, R.string.wallpaper_applied, - Toast.LENGTH_LONG).show(); + CafeBar.builder(context) + .theme(new CafeBarTheme.Custom(ColorHelper.getAttributeColor( + context, R.attr.card_background))) + .fitSystemWindow(R.bool.view_fitsystemwindow) + .content(R.string.wallpaper_applied) + .build().show(); } else { Toast.makeText(context, R.string.wallpaper_apply_failed, Toast.LENGTH_LONG).show(); diff --git a/library/src/main/java/com/dm/wallpaper/board/items/Setting.java b/library/src/main/java/com/dm/wallpaper/board/items/Setting.java new file mode 100644 index 00000000..f9a29970 --- /dev/null +++ b/library/src/main/java/com/dm/wallpaper/board/items/Setting.java @@ -0,0 +1,95 @@ +package com.dm.wallpaper.board.items; + +import android.support.annotation.DrawableRes; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; + +/* + * Wallpaper Board + * + * Copyright (c) 2017 Dani Mahardhika + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class Setting { + + private final int mIcon; + private final String mTitle; + private final String mSubtitle; + private final String mContent; + private String mFooter; + private final Setting.Type mType; + private final int mCheckState; + + public Setting(@DrawableRes int icon, String title, String subtitle, String content, String footer, + @NonNull Setting.Type type, @IntRange(from = -1, to = 1) int checkState) { + mIcon = icon; + mTitle = title; + mSubtitle = subtitle; + mContent = content; + mFooter = footer; + mType = type; + mCheckState = checkState; + } + + @DrawableRes + public int getIcon() { + return mIcon; + } + + public String getTitle() { + return mTitle; + } + + public String getSubtitle() { + return mSubtitle; + } + + public String getContent() { + return mContent; + } + + public String getFooter() { + return mFooter; + } + + public Setting.Type getType() { + return mType; + } + + public int getCheckState() { + return mCheckState; + } + + public void setFooter(String footer) { + mFooter = footer; + } + + public enum Type { + HEADER(0), + CACHE(1), + THEME(2), + WALLPAPER(3); + + private final int mType; + + Type(int type) { + mType = type; + } + + public int getType() { + return mType; + } + } +} diff --git a/library/src/main/java/com/dm/wallpaper/board/items/WallpaperJson.java b/library/src/main/java/com/dm/wallpaper/board/items/WallpaperJson.java index f2bdbd19..a25fb061 100644 --- a/library/src/main/java/com/dm/wallpaper/board/items/WallpaperJson.java +++ b/library/src/main/java/com/dm/wallpaper/board/items/WallpaperJson.java @@ -26,19 +26,19 @@ @JsonObject public class WallpaperJson { - @JsonField(name = "name") + @JsonField public String name; - @JsonField(name = "author") + @JsonField public String author; - @JsonField(name = "url") + @JsonField public String url; - @JsonField(name = "thumbUrl") + @JsonField public String thumbUrl; - @JsonField(name = "category") + @JsonField public String category; @JsonField(name = "Wallpapers") diff --git a/library/src/main/java/com/dm/wallpaper/board/preferences/Preferences.java b/library/src/main/java/com/dm/wallpaper/board/preferences/Preferences.java index ac9214a8..54adf8c7 100644 --- a/library/src/main/java/com/dm/wallpaper/board/preferences/Preferences.java +++ b/library/src/main/java/com/dm/wallpaper/board/preferences/Preferences.java @@ -1,5 +1,10 @@ package com.dm.wallpaper.board.preferences; +import android.content.Context; +import android.support.annotation.NonNull; + +import com.dm.wallpaper.board.helpers.PreferencesHelper; + /* * Wallpaper Board * @@ -18,15 +23,10 @@ * limitations under the License. */ -import android.content.Context; -import android.support.annotation.NonNull; - -import com.dm.wallpaper.board.helpers.PreferencesHelper; - public class Preferences { + @NonNull public static PreferencesHelper getPreferences(@NonNull Context context) { return new PreferencesHelper(context); } - } diff --git a/library/src/main/java/com/dm/wallpaper/board/receivers/WallpaperBoardReceiver.java b/library/src/main/java/com/dm/wallpaper/board/receivers/WallpaperBoardReceiver.java index bd3b2cab..ffb6beb5 100644 --- a/library/src/main/java/com/dm/wallpaper/board/receivers/WallpaperBoardReceiver.java +++ b/library/src/main/java/com/dm/wallpaper/board/receivers/WallpaperBoardReceiver.java @@ -3,7 +3,9 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.util.Log; +import com.dm.wallpaper.board.utils.LogUtil; import com.dm.wallpaper.board.utils.listeners.WallpaperBoardListener; /* @@ -30,7 +32,11 @@ public class WallpaperBoardReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - WallpaperBoardListener listener = (WallpaperBoardListener) context; - listener.OnWallpapersChecked(intent); + try { + WallpaperBoardListener listener = (WallpaperBoardListener) context; + listener.onWallpapersChecked(intent); + } catch (Exception e) { + LogUtil.e(Log.getStackTraceString(e)); + } } } diff --git a/library/src/main/java/com/dm/wallpaper/board/services/WallpaperBoardService.java b/library/src/main/java/com/dm/wallpaper/board/services/WallpaperBoardService.java index 682b6947..e356347b 100644 --- a/library/src/main/java/com/dm/wallpaper/board/services/WallpaperBoardService.java +++ b/library/src/main/java/com/dm/wallpaper/board/services/WallpaperBoardService.java @@ -10,6 +10,7 @@ import com.dm.wallpaper.board.items.WallpaperJson; import com.dm.wallpaper.board.receivers.WallpaperBoardReceiver; import com.dm.wallpaper.board.utils.Extras; +import com.dm.wallpaper.board.utils.LogUtil; import java.io.InputStream; import java.net.HttpURLConnection; @@ -61,11 +62,12 @@ protected void onHandleIntent(Intent intent) { if (wallpapersJson == null) return; int size = wallpapersJson.getWallpapers.size(); + broadcastIntent.putExtra(Extras.EXTRA_PACKAGE_NAME, getPackageName()); broadcastIntent.putExtra(Extras.EXTRA_SIZE, size); sendBroadcast(broadcastIntent); } } catch (Exception e) { - Log.d(Extras.LOG_TAG, Log.getStackTraceString(e)); + LogUtil.e(Log.getStackTraceString(e)); } } } diff --git a/library/src/main/java/com/dm/wallpaper/board/utils/Animator.java b/library/src/main/java/com/dm/wallpaper/board/utils/Animator.java index 992c0202..aafb09c1 100644 --- a/library/src/main/java/com/dm/wallpaper/board/utils/Animator.java +++ b/library/src/main/java/com/dm/wallpaper/board/utils/Animator.java @@ -12,6 +12,7 @@ import android.view.animation.AnimationUtils; import com.dm.wallpaper.board.R; +import com.dm.wallpaper.board.helpers.ContextHelper; /* * Wallpaper Board @@ -44,26 +45,11 @@ public static void startAlphaAnimation(@Nullable View view, long duration, int v view.startAnimation(alphaAnimation); } - public static void startSlideDownAnimation(@NonNull Context context, @NonNull View view, @Nullable View view2) { - Animation slideDown = AnimationUtils.loadAnimation(context, R.anim.slide_down_from_top); - slideDown.setAnimationListener(new Animation.AnimationListener() { - @Override - public void onAnimationStart(Animation animation) { - - } - - @Override - public void onAnimationEnd(Animation animation) { - if (view2 != null) startAlphaAnimation(view2, 200, View.VISIBLE); - } - - @Override - public void onAnimationRepeat(Animation animation) { - - } - }); - view.startAnimation(slideDown); - view.setVisibility(View.VISIBLE); + public static void startSlideDownAnimation(@NonNull View view, int visibility) { + Context context = ContextHelper.getBaseContext(view); + Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_down_from_top); + view.startAnimation(animation); + view.setVisibility(visibility); } public static void showFab(@Nullable FloatingActionButton fab) { @@ -82,5 +68,4 @@ public static void showFab(@Nullable FloatingActionButton fab) { fab.animate().setDuration(200).scaleX(1).scaleY(1).alpha(1) .setInterpolator(new LinearOutSlowInInterpolator()); } - } diff --git a/library/src/main/java/com/dm/wallpaper/board/utils/Extras.java b/library/src/main/java/com/dm/wallpaper/board/utils/Extras.java index 44fdf1cc..be30cd3a 100644 --- a/library/src/main/java/com/dm/wallpaper/board/utils/Extras.java +++ b/library/src/main/java/com/dm/wallpaper/board/utils/Extras.java @@ -31,13 +31,14 @@ public class Extras { public static final String EXTRA_NAME = "name"; public static final String EXTRA_AUTHOR = "author"; public static final String EXTRA_IMAGE = "image"; + public static final String EXTRA_SIZE = "size"; + public static final String EXTRA_PACKAGE_NAME = "packageName"; + public static final String EXTRA_KEY = "key"; public static final String EXTRA_PRODUCT_ID = "productId"; public static final String EXTRA_TYPE = "type"; public static final int TYPE_CONTRIBUTORS = 1; - public static final String LOG_TAG = "WallpaperBoard"; - } diff --git a/library/src/main/java/com/dm/wallpaper/board/utils/ImageConfig.java b/library/src/main/java/com/dm/wallpaper/board/utils/ImageConfig.java index 33337784..4ff661b5 100644 --- a/library/src/main/java/com/dm/wallpaper/board/utils/ImageConfig.java +++ b/library/src/main/java/com/dm/wallpaper/board/utils/ImageConfig.java @@ -5,6 +5,7 @@ import android.support.annotation.NonNull; import com.dm.wallpaper.board.R; +import com.dm.wallpaper.board.helpers.FileHelper; import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; @@ -40,23 +41,24 @@ public static ImageLoaderConfiguration getImageLoaderConfiguration(@NonNull Cont L.writeLogs(false); L.writeDebugLogs(false); return new ImageLoaderConfiguration.Builder(context) - .diskCacheSize(200 * 1024 * 1024) .threadPriority(Thread.NORM_PRIORITY - 2) .threadPoolSize(4) .tasksProcessingOrder(QueueProcessingType.FIFO) + .diskCacheSize(256 * FileHelper.MB) .diskCache(new UnlimitedDiskCache(new File( context.getCacheDir().toString() + "/uil-images"))) + .memoryCacheSize(6 * FileHelper.MB) .build(); } - public static DisplayImageOptions getDefaultImageOptions(boolean cacheOnDisk) { + public static DisplayImageOptions getDefaultImageOptions() { DisplayImageOptions.Builder options = new DisplayImageOptions.Builder(); options.delayBeforeLoading(10) .resetViewBeforeLoading(true) .bitmapConfig(Bitmap.Config.RGB_565) .imageScaleType(ImageScaleType.EXACTLY) .displayer(new FadeInBitmapDisplayer(700)) - .cacheOnDisk(cacheOnDisk) + .cacheOnDisk(true) .cacheInMemory(false); return options.build(); } @@ -84,6 +86,5 @@ public static ImageSize getThumbnailSize(@NonNull Context context) { if (quality <= 0) quality = 1; return new ImageSize((50 * quality), (50 * quality)); } - } diff --git a/library/src/main/java/com/dm/wallpaper/board/utils/LogUtil.java b/library/src/main/java/com/dm/wallpaper/board/utils/LogUtil.java new file mode 100644 index 00000000..4988875d --- /dev/null +++ b/library/src/main/java/com/dm/wallpaper/board/utils/LogUtil.java @@ -0,0 +1,42 @@ +package com.dm.wallpaper.board.utils; + +import android.util.Log; + +/* + * Wallpaper Board + * + * Copyright (c) 2017 Dani Mahardhika + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class LogUtil { + + private static boolean sIsLoggingEnabled = false; + + private static final String TAG = "WallpaperBoard"; + + public static void setLoggingEnabled(boolean enabled) { + LogUtil.sIsLoggingEnabled = enabled; + } + + public static void d(String message) { + if (LogUtil.sIsLoggingEnabled) + Log.d(TAG, message); + } + + public static void e(String message) { + if (LogUtil.sIsLoggingEnabled) + Log.e(TAG, message); + } +} diff --git a/library/src/main/java/com/dm/wallpaper/board/utils/listeners/InAppBillingListener.java b/library/src/main/java/com/dm/wallpaper/board/utils/listeners/InAppBillingListener.java index 9d7d6348..fcd5b6f7 100644 --- a/library/src/main/java/com/dm/wallpaper/board/utils/listeners/InAppBillingListener.java +++ b/library/src/main/java/com/dm/wallpaper/board/utils/listeners/InAppBillingListener.java @@ -22,8 +22,8 @@ public interface InAppBillingListener { - void OnInAppBillingSelected(InAppBilling product); - void OnInAppBillingInitialized(boolean success); - void OnInAppBillingConsume(String productId); + void onInAppBillingSelected(InAppBilling product); + void onInAppBillingInitialized(boolean success); + void onInAppBillingConsume(String productId); } diff --git a/library/src/main/java/com/dm/wallpaper/board/utils/listeners/RefreshDurationListener.java b/library/src/main/java/com/dm/wallpaper/board/utils/listeners/RefreshDurationListener.java index 42886ec1..6070b98c 100644 --- a/library/src/main/java/com/dm/wallpaper/board/utils/listeners/RefreshDurationListener.java +++ b/library/src/main/java/com/dm/wallpaper/board/utils/listeners/RefreshDurationListener.java @@ -20,6 +20,6 @@ public interface RefreshDurationListener { - void OnRefreshDurationSet(int rotateTime, boolean isMinute); + void onRefreshDurationSet(int rotateTime, boolean isMinute); } diff --git a/library/src/main/java/com/dm/wallpaper/board/utils/listeners/SearchListener.java b/library/src/main/java/com/dm/wallpaper/board/utils/listeners/SearchListener.java index dc4f1c31..e33d4633 100644 --- a/library/src/main/java/com/dm/wallpaper/board/utils/listeners/SearchListener.java +++ b/library/src/main/java/com/dm/wallpaper/board/utils/listeners/SearchListener.java @@ -20,6 +20,6 @@ public interface SearchListener { - void OnSearchExpanded(boolean expand); + void onSearchExpanded(boolean expand); } diff --git a/library/src/main/java/com/dm/wallpaper/board/utils/listeners/WallpaperBoardListener.java b/library/src/main/java/com/dm/wallpaper/board/utils/listeners/WallpaperBoardListener.java index 4fe1b0bd..1510e4a7 100644 --- a/library/src/main/java/com/dm/wallpaper/board/utils/listeners/WallpaperBoardListener.java +++ b/library/src/main/java/com/dm/wallpaper/board/utils/listeners/WallpaperBoardListener.java @@ -23,6 +23,6 @@ public interface WallpaperBoardListener { - void OnWallpapersChecked(@Nullable Intent intent); + void onWallpapersChecked(@Nullable Intent intent); } diff --git a/library/src/main/java/com/dm/wallpaper/board/utils/listeners/WallpaperListener.java b/library/src/main/java/com/dm/wallpaper/board/utils/listeners/WallpaperListener.java index b546e267..5cb4494a 100644 --- a/library/src/main/java/com/dm/wallpaper/board/utils/listeners/WallpaperListener.java +++ b/library/src/main/java/com/dm/wallpaper/board/utils/listeners/WallpaperListener.java @@ -20,6 +20,6 @@ public interface WallpaperListener { - void OnWallpaperSelected(int position); + void onWallpaperSelected(int position); } diff --git a/library/src/main/java/com/dm/wallpaper/board/utils/views/HeaderView.java b/library/src/main/java/com/dm/wallpaper/board/utils/views/HeaderView.java new file mode 100644 index 00000000..202b6d3f --- /dev/null +++ b/library/src/main/java/com/dm/wallpaper/board/utils/views/HeaderView.java @@ -0,0 +1,51 @@ +package com.dm.wallpaper.board.utils.views; + +import android.content.Context; +import android.content.res.TypedArray; +import android.support.v7.widget.AppCompatImageView; +import android.util.AttributeSet; + +import com.dm.wallpaper.board.R; + +/* + * CandyBar - Material Dashboard + * + * Copyright (c) 2014-2016 Dani Mahardhika + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class HeaderView extends AppCompatImageView { + + private int mWidthRatio; + private int mHeightRatio; + + public HeaderView(Context context, AttributeSet attrs) { + super(context, attrs); + TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.HeaderView); + + try { + mWidthRatio = typedArray.getInteger(R.styleable.HeaderView_widthRatio, 16); + mHeightRatio = typedArray.getInteger(R.styleable.HeaderView_heightRatio, 9); + } finally { + typedArray.recycle(); + } + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + double height = (widthMeasureSpec/mWidthRatio) * mHeightRatio; + setMeasuredDimension(widthMeasureSpec, Double.valueOf(height).intValue()); + } +} diff --git a/library/src/main/res/drawable/ic_drawer_wallpapers.xml b/library/src/main/res/drawable/ic_drawer_wallpapers.xml index b2018595..9e2340bd 100644 --- a/library/src/main/res/drawable/ic_drawer_wallpapers.xml +++ b/library/src/main/res/drawable/ic_drawer_wallpapers.xml @@ -5,5 +5,5 @@ android:viewportHeight="24.0"> + android:pathData="M4,4h7L11,2L4,2c-1.1,0 -2,0.9 -2,2v7h2L4,4zM10,13l-4,5h12l-3,-4 -2.03,2.71L10,13zM17,8.5c0,-0.83 -0.67,-1.5 -1.5,-1.5S14,7.67 14,8.5s0.67,1.5 1.5,1.5S17,9.33 17,8.5zM20,2h-7v2h7v7h2L22,4c0,-1.1 -0.9,-2 -2,-2zM20,20h-7v2h7c1.1,0 2,-0.9 2,-2v-7h-2v7zM4,13L2,13v7c0,1.1 0.9,2 2,2h7v-2L4,20v-7z"/> diff --git a/library/src/main/res/drawable/ic_toolbar_close.xml b/library/src/main/res/drawable/ic_toolbar_close.xml index 7bf12e18..39ffa27c 100644 --- a/library/src/main/res/drawable/ic_toolbar_close.xml +++ b/library/src/main/res/drawable/ic_toolbar_close.xml @@ -4,6 +4,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/library/src/main/res/drawable/ic_toolbar_storage.xml b/library/src/main/res/drawable/ic_toolbar_storage.xml new file mode 100644 index 00000000..53c595cd --- /dev/null +++ b/library/src/main/res/drawable/ic_toolbar_storage.xml @@ -0,0 +1,9 @@ + + + diff --git a/library/src/main/res/drawable/ic_toolbar_theme.xml b/library/src/main/res/drawable/ic_toolbar_theme.xml new file mode 100644 index 00000000..e3f120f8 --- /dev/null +++ b/library/src/main/res/drawable/ic_toolbar_theme.xml @@ -0,0 +1,9 @@ + + + diff --git a/library/src/main/res/drawable/ic_toolbar_wallpapers.xml b/library/src/main/res/drawable/ic_toolbar_wallpapers.xml new file mode 100644 index 00000000..9e2340bd --- /dev/null +++ b/library/src/main/res/drawable/ic_toolbar_wallpapers.xml @@ -0,0 +1,9 @@ + + + diff --git a/library/src/main/res/drawable/navigation_view_item_background.xml b/library/src/main/res/drawable/navigation_view_item_background.xml new file mode 100644 index 00000000..02a81bcd --- /dev/null +++ b/library/src/main/res/drawable/navigation_view_item_background.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/library/src/main/res/drawable/navigation_view_item_background_dark.xml b/library/src/main/res/drawable/navigation_view_item_background_dark.xml new file mode 100644 index 00000000..3d27cb6a --- /dev/null +++ b/library/src/main/res/drawable/navigation_view_item_background_dark.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/library/src/main/res/layout-land/fragment_about_item_footer.xml b/library/src/main/res/layout-land/fragment_about_item_footer.xml new file mode 100644 index 00000000..75724ed7 --- /dev/null +++ b/library/src/main/res/layout-land/fragment_about_item_footer.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/library/src/main/res/layout-land/fragment_about_item_header.xml b/library/src/main/res/layout-land/fragment_about_item_header.xml new file mode 100644 index 00000000..61e9f70b --- /dev/null +++ b/library/src/main/res/layout-land/fragment_about_item_header.xml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/library/src/main/res/layout-land/fragment_about_item_sub.xml b/library/src/main/res/layout-land/fragment_about_item_sub.xml new file mode 100644 index 00000000..f9231855 --- /dev/null +++ b/library/src/main/res/layout-land/fragment_about_item_sub.xml @@ -0,0 +1,38 @@ + + + + + + + + + + \ No newline at end of file diff --git a/library/src/main/res/layout-v21/fragment_wallpapers_item_grid.xml b/library/src/main/res/layout-v21/fragment_wallpapers_item_grid.xml new file mode 100644 index 00000000..75ee9736 --- /dev/null +++ b/library/src/main/res/layout-v21/fragment_wallpapers_item_grid.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/library/src/main/res/layout/activity_muzei.xml b/library/src/main/res/layout/activity_muzei.xml index 48372a05..7baf06ab 100644 --- a/library/src/main/res/layout/activity_muzei.xml +++ b/library/src/main/res/layout/activity_muzei.xml @@ -13,15 +13,14 @@ android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:minHeight="?attr/actionBarSize" - android:background="?attr/toolbar_color" - app:theme="@style/ToolbarStyle"> + android:background="?attr/colorPrimary"> - - - - - - - - - - - - - + - + android:layout_height="wrap_content" + android:clipToPadding="false"> + + + + + + + + + + + + + + + + - @@ -19,25 +19,6 @@ android:layout_height="match_parent" android:fitsSystemWindows="true"> - - - - - - @@ -89,4 +70,15 @@ android:visibility="gone" style="?android:attr/progressBarStyleLarge"/> - \ No newline at end of file + + + \ No newline at end of file diff --git a/library/src/main/res/layout/fragment_about.xml b/library/src/main/res/layout/fragment_about.xml index 44e771b8..26cd26d1 100644 --- a/library/src/main/res/layout/fragment_about.xml +++ b/library/src/main/res/layout/fragment_about.xml @@ -1,316 +1,14 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:clipToPadding="false"/> + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/library/src/main/res/layout/fragment_about_item_header.xml b/library/src/main/res/layout/fragment_about_item_header.xml new file mode 100644 index 00000000..ee6a8991 --- /dev/null +++ b/library/src/main/res/layout/fragment_about_item_header.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/library/src/main/res/layout/fragment_about_item_sub.xml b/library/src/main/res/layout/fragment_about_item_sub.xml new file mode 100644 index 00000000..36fbb9b4 --- /dev/null +++ b/library/src/main/res/layout/fragment_about_item_sub.xml @@ -0,0 +1,29 @@ + + + + + + + + \ No newline at end of file diff --git a/library/src/main/res/layout/fragment_credits_item_list.xml b/library/src/main/res/layout/fragment_credits_item_list.xml index b4e7cbe8..fa6ff30f 100644 --- a/library/src/main/res/layout/fragment_credits_item_list.xml +++ b/library/src/main/res/layout/fragment_credits_item_list.xml @@ -2,25 +2,24 @@ + android:theme="@style/ButtonStyle"> @@ -29,10 +28,10 @@ android:id="@+id/subtitle" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingLeft="@dimen/card_padding" - android:paddingStart="@dimen/card_padding" - android:paddingRight="@dimen/card_padding" - android:paddingEnd="@dimen/card_padding" + android:paddingLeft="@dimen/content_margin" + android:paddingStart="@dimen/content_margin" + android:paddingRight="@dimen/content_margin" + android:paddingEnd="@dimen/content_margin" android:textColor="?android:attr/textColorSecondary" android:textSize="@dimen/text_content" fontPath="fonts/Font-Regular.ttf"/> diff --git a/library/src/main/res/layout/fragment_filter_item_list.xml b/library/src/main/res/layout/fragment_filter_item_list.xml index 1741b9a0..dc0d2127 100644 --- a/library/src/main/res/layout/fragment_filter_item_list.xml +++ b/library/src/main/res/layout/fragment_filter_item_list.xml @@ -1,7 +1,6 @@ + android:theme="@style/ButtonStyle"> + android:theme="@style/CheckBoxStyle"/> diff --git a/library/src/main/res/layout/fragment_settings.xml b/library/src/main/res/layout/fragment_settings.xml index 0714d125..26cd26d1 100644 --- a/library/src/main/res/layout/fragment_settings.xml +++ b/library/src/main/res/layout/fragment_settings.xml @@ -1,155 +1,14 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:clipToPadding="false"/> + + + + + \ No newline at end of file diff --git a/library/src/main/res/layout/fragment_settings_item_list.xml b/library/src/main/res/layout/fragment_settings_item_list.xml new file mode 100644 index 00000000..9d94cd3b --- /dev/null +++ b/library/src/main/res/layout/fragment_settings_item_list.xml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/library/src/main/res/layout/fragment_wallpapers.xml b/library/src/main/res/layout/fragment_wallpapers.xml index 0f2a24df..5d2466cf 100644 --- a/library/src/main/res/layout/fragment_wallpapers.xml +++ b/library/src/main/res/layout/fragment_wallpapers.xml @@ -20,19 +20,13 @@ android:paddingStart="@dimen/card_margin_left" android:paddingLeft="@dimen/card_margin_left" android:paddingBottom="@dimen/card_margin_bottom" - android:clipToPadding="false"/> + android:clipToPadding="false" + android:scrollbars="vertical" + android:scrollbarThumbVertical="?attr/colorAccent" + android:scrollbarSize="4dp"/> - - + android:theme="@style/ButtonStyle"> - + android:scaleType="centerCrop" + app:heightRatio="1" + app:widthRatio="1"/> @@ -59,7 +66,7 @@ android:layout_height="wrap_content" android:textColor="?android:attr/textColorSecondary" android:textSize="@dimen/text_content" - android:singleLine="true" + android:maxLines="1" android:ellipsize="end" fontPath="fonts/Font-Regular.ttf"/> @@ -73,7 +80,7 @@ android:layout_marginRight="@dimen/content_padding" android:layout_marginEnd="@dimen/content_padding" android:background="?attr/selectableItemBackgroundBorderless" - app:theme="@style/ButtonStyle"/> + android:theme="@style/ButtonStyle"/> diff --git a/library/src/main/res/raw/licenses.html b/library/src/main/res/raw/licenses.html index 0d7830f9..2204866f 100644 --- a/library/src/main/res/raw/licenses.html +++ b/library/src/main/res/raw/licenses.html @@ -204,25 +204,6 @@
 Copyright (c) 2016 Lopez Mikhael
 
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-   http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
-
    -
  • RecyclerView Fast Scroll
  • -
- -
-Copyright (c) 2016 Daniel Ciao
-
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
diff --git a/library/src/main/res/values-land-v21/bools.xml b/library/src/main/res/values-land-v21/bools.xml
new file mode 100644
index 00000000..86819724
--- /dev/null
+++ b/library/src/main/res/values-land-v21/bools.xml
@@ -0,0 +1,7 @@
+
+
+
+    
+    false
+
+
\ No newline at end of file
diff --git a/library/src/main/res/values-land/integers.xml b/library/src/main/res/values-land/integers.xml
index 33b0a205..355d8e56 100644
--- a/library/src/main/res/values-land/integers.xml
+++ b/library/src/main/res/values-land/integers.xml
@@ -1,6 +1,8 @@
 
 
 
-    3
+    3
+
+    2
 
 
\ No newline at end of file
diff --git a/library/src/main/res/values-sw600dp-land/integers.xml b/library/src/main/res/values-sw600dp-land/integers.xml
index 907238db..9da068aa 100644
--- a/library/src/main/res/values-sw600dp-land/integers.xml
+++ b/library/src/main/res/values-sw600dp-land/integers.xml
@@ -1,6 +1,6 @@
 
 
 
-    4
+    4
 
 
\ No newline at end of file
diff --git a/library/src/main/res/values-sw600dp-v21/bools.xml b/library/src/main/res/values-sw600dp-v21/bools.xml
new file mode 100644
index 00000000..680070df
--- /dev/null
+++ b/library/src/main/res/values-sw600dp-v21/bools.xml
@@ -0,0 +1,7 @@
+
+
+
+    
+    true
+
+
\ No newline at end of file
diff --git a/library/src/main/res/values-sw600dp/dimens.xml b/library/src/main/res/values-sw600dp/dimens.xml
index 93213b51..9e8d8f79 100644
--- a/library/src/main/res/values-sw600dp/dimens.xml
+++ b/library/src/main/res/values-sw600dp/dimens.xml
@@ -6,7 +6,8 @@
     16sp
 
     
-    110dp
-    180dp
+    140dp
+    4dp
+    -70dp
 
 
\ No newline at end of file
diff --git a/library/src/main/res/values-sw600dp/integers.xml b/library/src/main/res/values-sw600dp/integers.xml
index 33b0a205..876ac150 100644
--- a/library/src/main/res/values-sw600dp/integers.xml
+++ b/library/src/main/res/values-sw600dp/integers.xml
@@ -1,6 +1,6 @@
 
 
 
-    3
+    3
 
 
\ No newline at end of file
diff --git a/library/src/main/res/values-v21/bools.xml b/library/src/main/res/values-v21/bools.xml
index 838ec48b..c6c21f45 100644
--- a/library/src/main/res/values-v21/bools.xml
+++ b/library/src/main/res/values-v21/bools.xml
@@ -4,6 +4,7 @@
     
     false
 
-    false
+    
+    true
 
 
\ No newline at end of file
diff --git a/library/src/main/res/values-v21/dimens.xml b/library/src/main/res/values-v21/dimens.xml
index 48250c3c..b19a033d 100644
--- a/library/src/main/res/values-v21/dimens.xml
+++ b/library/src/main/res/values-v21/dimens.xml
@@ -6,8 +6,7 @@
     4dp
     4dp
     4dp
-    4dp
-    2.5dp
+
     2dp
 
 
\ No newline at end of file
diff --git a/library/src/main/res/values-v21/styles.xml b/library/src/main/res/values-v21/styles.xml
index 41041988..8ee14a92 100644
--- a/library/src/main/res/values-v21/styles.xml
+++ b/library/src/main/res/values-v21/styles.xml
@@ -8,9 +8,8 @@
         true
         @android:transition/move
         @android:transition/move
-        true
         @android:color/transparent
-        true
+        true
         true
     
 
@@ -21,10 +20,40 @@
         true
         @android:transition/move
         @android:transition/move
-        true
         @android:color/transparent
-        true
+        true
         true
     
 
+    
+    
+
+    
+    
+
+
+    
+    
+
+    
+    
+
 
\ No newline at end of file
diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml
index 9473c2f0..33442e12 100644
--- a/library/src/main/res/values/attrs.xml
+++ b/library/src/main/res/values/attrs.xml
@@ -6,15 +6,12 @@
     
     
     
-    
 
-    
-    
     
-    
 
-    
-    
-    
+    
+        
+        
+    
 
 
\ No newline at end of file
diff --git a/library/src/main/res/values/bools.xml b/library/src/main/res/values/bools.xml
index d5ad3f2e..d0bce076 100644
--- a/library/src/main/res/values/bools.xml
+++ b/library/src/main/res/values/bools.xml
@@ -4,4 +4,9 @@
     
     true
 
+    false
+
+    
+    false
+
 
\ No newline at end of file
diff --git a/library/src/main/res/values/colors.xml b/library/src/main/res/values/colors.xml
index f5aacbad..2dab3084 100644
--- a/library/src/main/res/values/colors.xml
+++ b/library/src/main/res/values/colors.xml
@@ -1,71 +1,62 @@
 
 
 
-    #828282
-    #E0E0E0
-    #F44336
+    #DC4316
+    #C43916
+    #F25A16
 
-    #FFFFFF
-    #121212
-    #F44336
+    #DC4316
+    #C43916
+    #F25A16
 
     
     #F2F2F2
 
     
-    #F5F5F5
-    #181818
-    #424242
-    #BBFFFFFF
-    #44FFFFFF
-    #44FFFFFF
-
-    
-    #F5F5F5
-    #181818
-    #424242
-    #DDFFFFFF
-    #44000000
-    #44FFFFFF
-
-    
-    #F44336
-    #FFFFFF
+    #FFFFFF
+    #FFFFFF
 
     
     #FFFFFF
     #55000000
-    #484848
-    #DDFFFFFF
-    #F44336
-    #F44336
+
+    #D9000000
+    #FFFFFF
+    #DC4316
+    #DC4316
+    #00000000
+    #00000000
+
+    
+    #F25A16
+    #FFFFFF
 
     
     #FFFFFF
-    #181818
-    #55000000
-    #55FFFFFF
-    #44F44336
-    #44F44336
+    #222222
+
+    
+    #4D000000
+    #4DFFFFFF
+    #44DC4316
+    #44DC4316
 
     
-    #FAFAFA
-    #000000
-    #484848
-    #EEFFFFFF
-    #777777
-    #99FFFFFF
-    #EEEEEE
-    #22FFFFFF
+    #EAEAEA
+    #181818
+    #D9000000
+    #FFFFFF
+    #8C000000
+    #B3FFFFFF
 
-    #666666
-    #BBBBBB
+    #18000000
+    #18FFFFFF
 
     
-    #F44336
+    #DC4316
 
     
-    #88000000
+    #AA000000
     #66000000
 
 
diff --git a/library/src/main/res/values/dashboard_strings.xml b/library/src/main/res/values/dashboard_strings.xml
index 584f481d..2dbaeb13 100644
--- a/library/src/main/res/values/dashboard_strings.xml
+++ b/library/src/main/res/values/dashboard_strings.xml
@@ -48,6 +48,9 @@
     Dashboard will apply wallpaper based on current view of wallpaper.
         Drag to left or right to adjust wallpaper. Pinch or double tap to zoom wallpaper.
 
+    %s added to favorite
+    %s removed from favorite
+
     
     Minute
     Hour
@@ -73,18 +76,21 @@
     Unable to load InApp Purchase products
 
     
+    Data & Cache
     Clear Cache
     Remove image cache from your storage created
         after loading cloud wallpaper thumbnails
-    Cache Size :
+    Cache Size: %s
     Cache Cleared
     Do you really want to clear cache?
 
+    Theme
     Dark Theme
     Switch between dark or light theme
 
+    Wallpaper
     Wallpaper Save Location
-    Try to download at least one wallpaper first.
+    Try to download at least one wallpaper first
 
     
     Storage permission needed to save wallpaper
@@ -102,7 +108,7 @@
     Unable to check license, please try again in a few moments
 
     
-    No result found for %s
+    No result found for \"%s\"
 
     
     Crash Report
@@ -122,7 +128,6 @@
 
     
     Wallpaper Board
-    Preparing %s …
 
     
     Open
diff --git a/library/src/main/res/values/dimens.xml b/library/src/main/res/values/dimens.xml
index c07c0dd1..ae6d882f 100644
--- a/library/src/main/res/values/dimens.xml
+++ b/library/src/main/res/values/dimens.xml
@@ -2,37 +2,40 @@
 
 
     16dp
-    6dp
+    8dp
+
+    1dp
 
     
-    14dp
     3dp
     3dp
     4dp
     1dp
+
     4dp
-    2.5dp
+
+    2dp
     0dp
 
     
     56dp
 
     
-    40dp
+    50dp
 
     
-    8dp
+    4dp
 
     
-    20dp
+    24dp
     8dp
 
     
     10dp
 
     
-    22sp
     20sp
+    24sp
     18sp
     16sp
     15sp
@@ -42,8 +45,12 @@
     96dp
     14sp
 
+    
+    40dp
+
     
-    96dp
-    120dp
+    120dp
+    3dp
+    -60dp
 
 
\ No newline at end of file
diff --git a/library/src/main/res/values/integers.xml b/library/src/main/res/values/integers.xml
index 98b9d942..10a2484b 100644
--- a/library/src/main/res/values/integers.xml
+++ b/library/src/main/res/values/integers.xml
@@ -1,6 +1,8 @@
 
 
 
-    2
+    2
+
+    1
 
 
\ No newline at end of file
diff --git a/library/src/main/res/values/styles.xml b/library/src/main/res/values/styles.xml
index be915114..458eae79 100644
--- a/library/src/main/res/values/styles.xml
+++ b/library/src/main/res/values/styles.xml
@@ -3,13 +3,11 @@
     
     
 
     
     
 
     
@@ -17,27 +15,25 @@
         @color/colorPrimary
         @color/colorPrimaryDark
         @color/colorAccent
+        @color/toolbarIcon
+        @color/primaryText
+        @color/secondaryText
+        @color/dividerList
+        @color/mainBackground
         true
         false
         true
         @null
         @style/DrawerArrowStyle
-        @color/primaryText
-        @color/secondaryText
+        @drawable/ic_toolbar_back
 
         @color/mainBackground
         @color/cardBackground
         @color/rippleColor
         @color/rippleAccent
         @color/dividerList
-        @color/fastScrollTrack
-        @color/toolbar
-        @color/colorAccent
+
         @color/toolbarIcon
-        @color/toolbarHintText
-        @color/searchToolbar
-        @color/searchToolbarIcon
-        @color/searchToolbarHintText
 
         @color/colorAccent
         @color/primaryText
@@ -53,27 +49,25 @@
         @color/darkColorPrimary
         @color/darkColorPrimaryDark
         @color/darkColorAccent
+        @color/toolbarIconDark
+        @color/primaryTextDark
+        @color/secondaryTextDark
+        @color/dividerListDark
+        @color/mainBackgroundDark
         true
         false
         true
         @null
         @style/DrawerArrowStyle
-        @color/primaryTextDark
-        @color/secondaryTextDark
+        @drawable/ic_toolbar_back
 
         @color/mainBackgroundDark
         @color/cardBackgroundDark
         @color/rippleColorDark
         @color/rippleAccentDark
         @color/dividerListDark
-        @color/fastScrollTrackDark
-        @color/toolbarDark
-        @color/darkColorAccent
+
         @color/toolbarIconDark
-        @color/toolbarHintTextDark
-        @color/searchToolbarDark
-        @color/searchToolbarIconDark
-        @color/searchToolbarHintTextDark
 
         @color/cardBackgroundDark
         @color/darkColorAccent
@@ -123,35 +117,19 @@
         48dp
     
 
-    
-
-    
-
     
 
     
 
     
 
-    
-