Skip to content

Commit

Permalink
1. Remove live wallpaper draw loading text
Browse files Browse the repository at this point in the history
2. Add Japanese translation, thanks to Rintan.
3. Add translator Activity.
  • Loading branch information
liaoheng committed Jul 1, 2021
1 parent f00e1c7 commit bf6c568
Show file tree
Hide file tree
Showing 18 changed files with 464 additions and 95 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
applicationId "me.liaoheng.wallpaper"
versionCode 10923
versionName "1.9.23"
versionCode 10924
versionName "1.9.24"
}

def isSigning = true
Expand Down Expand Up @@ -104,7 +104,7 @@ dependencies {
implementation 'com.github.Commit451:NativeStackBlur:1.0.5'

//https://github.com/scottyab/rootbeer
implementation 'com.github.scottyab:rootbeer:0.0.8'
implementation 'com.github.scottyab:rootbeer:0.1.0'

//https://github.com/Clans/FloatingActionButton
implementation 'com.github.clans:fab:1.6.4'
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
android:name=".ui.LicenseActivity"
android:configChanges="screenSize|orientation|keyboardHidden"
android:label="@string/open_source_license" />
<activity
android:name=".ui.TranslatorActivity"
android:configChanges="screenSize|orientation|keyboardHidden"
android:label="Translator" />
<activity
android:name=".ui.WallpaperHistoryListActivity"
android:configChanges="screenSize|orientation|keyboardHidden"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.github.liaoheng.common.util.AppUtils;
import com.github.liaoheng.common.util.Callback;
import com.github.liaoheng.common.util.DisplayUtils;
import com.github.liaoheng.common.util.L;
import com.github.liaoheng.common.util.ROM;
import com.github.liaoheng.common.util.Utils;
Expand Down Expand Up @@ -152,7 +151,6 @@ public void setBingWallpaper(Wallpaper image, Config config) {
}

public void setBingWallpaper(Observable<DownloadBitmap> observable, Config config) {
drawLoading();
Utils.addSubscribe(
observable.subscribeOn(Schedulers.io()).compose(download(config)),
new Callback.EmptyCallback<DownloadBitmap>() {
Expand All @@ -165,7 +163,6 @@ public void onSuccess(DownloadBitmap d) {

@Override
public void onError(Throwable e) {
drawError(R.string.set_wallpaper_failure);
mServiceHelper.failure(config, e);
}
});
Expand Down Expand Up @@ -232,8 +229,6 @@ private ObservableTransformer<DownloadBitmap, DownloadBitmap> download(Config co
});
}

private File mCurWallpaper;

private void setWallpaper(Config config, DownloadBitmap d) {
if (config.isBackground()) {
WallpaperUtils.autoSaveWallpaper(getApplicationContext(), TAG, d.image, d.original);
Expand Down Expand Up @@ -267,24 +262,7 @@ private void setWallpaper(Config config, DownloadBitmap d) {
}
}

private void drawLoading() {
WallpaperUtils.drawSurfaceHolder(getSurfaceHolder(), canvas -> {
draw(canvas, mCurWallpaper);
WallpaperUtils.drawText(canvas, getResources().getString(R.string.loading),
DisplayUtils.dp2px(getApplicationContext(), 23), width, height);
});
}

private void drawError(int text) {
WallpaperUtils.drawSurfaceHolder(getSurfaceHolder(), canvas -> {
draw(canvas, mCurWallpaper);
WallpaperUtils.drawText(canvas, getResources().getString(text),
DisplayUtils.dp2px(getApplicationContext(), 19), width, height);
});
}

private void drawWallpaper(File file) {
mCurWallpaper = new File(file.toURI());
WallpaperUtils.drawSurfaceHolder(getSurfaceHolder(), canvas -> draw(canvas, file));
}

Expand Down Expand Up @@ -353,7 +331,6 @@ public void onSuccess(DownloadBitmap d) {

@Override
public void onError(Throwable e) {
drawError(R.string.load_image_error);
mServiceHelper.failure(config, e);
}
});
Expand All @@ -363,7 +340,6 @@ public void onError(Throwable e) {
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(holder);
Utils.dispose(mLoadWallpaperDisposable);
mCurWallpaper = null;
destroy();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
* @version 2017-12-27 22:39
*/
public class LicenseActivity extends BaseActivity {
@BindView(R.id.license_recycler_view)
RecyclerView mRecyclerView;

class LicenseAdapter extends BaseRecyclerAdapter<License, LicenseViewHolder> {

Expand All @@ -42,8 +40,7 @@ public LicenseAdapter(Context context, List<License> list) {
@NonNull
@Override
public LicenseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = inflate(R.layout.view_license_list_item, parent);
return new LicenseViewHolder(view);
return new LicenseViewHolder(inflate(R.layout.view_license_list_item, parent));
}

@Override
Expand Down Expand Up @@ -98,6 +95,8 @@ public License(String name, String author, String url, String text) {
String text = "Apache License 2.0";
}

@BindView(R.id.license_recycler_view)
RecyclerView mRecyclerView;
@BindView(R.id.license_text)
TextView license;
@BindView(R.id.license_image)
Expand Down Expand Up @@ -155,6 +154,8 @@ protected void onCreate(Bundle savedInstanceState) {
"https://github.com/scottyab/rootbeer"));
licenses.add(new License("joda-time-android", "dlew",
"https://github.com/dlew/joda-time-android"));
licenses.add(new License("sentry-java", "getsentry",
"https://github.com/getsentry/sentry-java","MIT"));

mRecyclerView.setAdapter(new LicenseAdapter(this, licenses));
}
Expand Down
40 changes: 15 additions & 25 deletions app/src/main/java/me/liaoheng/wallpaper/ui/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;

import com.github.liaoheng.common.util.AppUtils;
import com.github.liaoheng.common.util.Callback;
Expand All @@ -34,6 +22,16 @@

import org.joda.time.LocalTime;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
import me.liaoheng.wallpaper.R;
import me.liaoheng.wallpaper.util.BingWallpaperJobManager;
import me.liaoheng.wallpaper.util.BingWallpaperUtils;
Expand Down Expand Up @@ -67,17 +65,14 @@ public void onCreate(Bundle savedInstanceState) {
setTitle(R.string.menu_main_setting);
setContentView(R.layout.activity_settings);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState != null) {
isChangeLanguage = savedInstanceState.getBoolean("isChangeLanguage");
}
getSupportFragmentManager().beginTransaction()
.replace(R.id.settings_layout, new MyPreferenceFragment(), "SettingsFragment")
.commit();
}

@Override
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
isChangeLanguage = savedInstanceState.getBoolean("isChangeLanguage");
}

@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
Expand Down Expand Up @@ -240,13 +235,8 @@ public void onDeny() {
return true;
});

Preference translation = findPreference("pref_translation");
String translator = BingWallpaperUtils.getTranslator(getActivity());
if (!TextUtils.isEmpty(translator)) {
translation.setSummary(translator);
}
translation.setOnPreferenceClickListener(preference -> {
BingWallpaperUtils.openBrowser(getActivity(), "https://crowdin.com/project/starth-bing-wallpaper");
findPreference("pref_translation").setOnPreferenceClickListener(preference -> {
UIUtils.startActivity(getActivity(), TranslatorActivity.class);
return true;
});

Expand Down
156 changes: 156 additions & 0 deletions app/src/main/java/me/liaoheng/wallpaper/ui/TranslatorActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package me.liaoheng.wallpaper.ui;

import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.github.liaoheng.common.adapter.holder.BaseRecyclerViewHolder;
import com.github.liaoheng.common.adapter.model.Group;
import com.github.liaoheng.common.util.DisplayUtils;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import me.liaoheng.wallpaper.R;
import me.liaoheng.wallpaper.util.BaseGroupRecyclerAdapter;
import me.liaoheng.wallpaper.util.BingWallpaperUtils;

/**
* @author liaoheng
* @date 2021-07-01 10:32
*/
public class TranslatorActivity extends BaseActivity {
class TranslatorAdapter extends BaseGroupRecyclerAdapter<Translator> {

public TranslatorAdapter(Context context, List<Group<Translator>> list) {
super(context, list);
}

@Override
public BaseRecyclerViewHolder<Group<Translator>> onCreateGroupHeaderViewHolder(ViewGroup parent, int viewType) {
TextView textView = new TextView(getContext());
textView.setTextSize(DisplayUtils.sp2px(getContext(), 7));
int border = DisplayUtils.dp2px(getContext(), 3);
textView.setPadding(border, border, border, border);
return new TranslatorLanguageViewHolder(textView);
}

@Override
public BaseRecyclerViewHolder<Group<Translator>> onCreateGroupFooterViewHolder(ViewGroup parent, int viewType) {
return null;
}

@Override
public BaseRecyclerViewHolder<Group<Translator>> onCreateGroupContentViewHolder(ViewGroup parent,
int viewType) {
return new TranslatorViewHolder(inflate(R.layout.view_translator_list_item, parent));
}
}

class TranslatorLanguageViewHolder extends BaseRecyclerViewHolder<Group<Translator>> {

public TranslatorLanguageViewHolder(View itemView) {
super(itemView);
}

@Override
public void onHandle(@Nullable Group<Translator> item, int position) {
if (item == null) {
return;
}
((TextView) itemView).setText(item.getText());
}
}

class TranslatorViewHolder extends BaseRecyclerViewHolder<Group<Translator>> {

@BindView(R.id.translator_list_name)
TextView name;

public TranslatorViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}

@Override
public void onHandle(@Nullable Group<Translator> item, int position) {
if (item == null || item.getContent() == null) {
return;
}
itemView.setOnClickListener(v -> BingWallpaperUtils.openBrowser(getContext(), item.getContent().url));
name.setText(item.getContent().name);
}
}

static class Translator {
public Translator(String name, String url) {
this.name = name;
this.url = url;
}

String name;
String url;
}

@BindView(R.id.translator_recycler_view)
RecyclerView mRecyclerView;
@BindView(R.id.translator_desc)
TextView desc;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_translator);
ButterKnife.bind(this);
String text = "if you want to help translation the app, "
+ "please click: https://crowdin.com/project/starth-bing-wallpaper";
desc.setText(Html.fromHtml(text));

List<Group<Translator>> translators = new ArrayList<>();

translators.add(new Group<>(Group.GroupType.HEADER, "Polski(Polish)"));
addTranslator(translators, "@dekar16", "https://crowdin.com/profile/dekar16");

translators.add(new Group<>(Group.GroupType.HEADER, "Русский(Russian)"));
addTranslator(translators, "@tullev(Lev Tulubjev)", "https://crowdin.com/profile/tullev");
addTranslator(translators, "@FanHamMer(Oleg Popenkov)", "https://crowdin.com/profile/FanHamMer");

translators.add(new Group<>(Group.GroupType.HEADER, "Čeština(Czech)"));
addTranslator(translators, "@foreteller", "https://crowdin.com/profile/foreteller");

translators.add(new Group<>(Group.GroupType.HEADER, "Slovenčina(Slovak)"));
addTranslator(translators, "@foreteller", "https://crowdin.com/profile/foreteller");

translators.add(new Group<>(Group.GroupType.HEADER, "Deutsch(German)"));
addTranslator(translators, "@Bergradler", "https://crowdin.com/profile/Bergradler");

translators.add(new Group<>(Group.GroupType.HEADER, "Nederlands(Dutch)"));
addTranslator(translators, "@5qx9Pe7Lvj8Fn7zg(Jasper)", "https://crowdin.com/profile/5qx9Pe7Lvj8Fn7zg");

translators.add(new Group<>(Group.GroupType.HEADER, "Français(French)"));
addTranslator(translators, "@Faux-ami(Nicolas)", "https://crowdin.com/profile/Faux-ami");

translators.add(new Group<>(Group.GroupType.HEADER, "български(Bulgarian)"));
addTranslator(translators, "@trifon71(Trifon Ribnishki)", "https://crowdin.com/profile/trifon71");

translators.add(new Group<>(Group.GroupType.HEADER, "日本語(Japanese)"));
addTranslator(translators, "@Rintan", "https://crowdin.com/profile/rintan");
mRecyclerView.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setAdapter(new TranslatorAdapter(this, translators));

}

private void addTranslator(List<Group<Translator>> translators, String name, String url) {
translators.add(new Group<>(new Translator(name, url)));
}

}
Loading

0 comments on commit bf6c568

Please sign in to comment.