Merge branch 'feature/check-for-update-button' into fork
This commit is contained in:
commit
b6efafe99d
|
@ -26,6 +26,8 @@ import org.joinmastodon.android.api.MastodonAPIController;
|
||||||
import org.joinmastodon.android.events.SelfUpdateStateChangedEvent;
|
import org.joinmastodon.android.events.SelfUpdateStateChangedEvent;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -101,6 +103,12 @@ public class GithubSelfUpdaterImpl extends GithubSelfUpdater{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkForUpdates() {
|
||||||
|
setState(UpdateState.CHECKING);
|
||||||
|
MastodonAPIController.runInBackground(this::actuallyCheckForUpdates);
|
||||||
|
}
|
||||||
|
|
||||||
private void actuallyCheckForUpdates(){
|
private void actuallyCheckForUpdates(){
|
||||||
Request req=new Request.Builder()
|
Request req=new Request.Builder()
|
||||||
.url("https://api.github.com/repos/sk22/mastodon-android-fork/releases/latest")
|
.url("https://api.github.com/repos/sk22/mastodon-android-fork/releases/latest")
|
||||||
|
|
|
@ -15,6 +15,7 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowInsets;
|
import android.view.WindowInsets;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
import android.view.animation.AlphaAnimation;
|
||||||
import android.view.animation.LinearInterpolator;
|
import android.view.animation.LinearInterpolator;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
@ -71,6 +72,7 @@ public class SettingsFragment extends MastodonToolbarFragment{
|
||||||
private PushSubscription pushSubscription;
|
private PushSubscription pushSubscription;
|
||||||
|
|
||||||
private ImageView themeTransitionWindowView;
|
private ImageView themeTransitionWindowView;
|
||||||
|
private TextItem checkForUpdateItem;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState){
|
public void onCreate(Bundle savedInstanceState){
|
||||||
|
@ -118,6 +120,10 @@ public class SettingsFragment extends MastodonToolbarFragment{
|
||||||
items.add(new TextItem(R.string.settings_privacy_policy, ()->UiUtils.launchWebBrowser(getActivity(), "https://"+session.domain+"/terms")));
|
items.add(new TextItem(R.string.settings_privacy_policy, ()->UiUtils.launchWebBrowser(getActivity(), "https://"+session.domain+"/terms")));
|
||||||
|
|
||||||
items.add(new RedHeaderItem(R.string.settings_spicy));
|
items.add(new RedHeaderItem(R.string.settings_spicy));
|
||||||
|
if (GithubSelfUpdater.needSelfUpdating()) {
|
||||||
|
checkForUpdateItem = new TextItem(R.string.check_for_update, GithubSelfUpdater.getInstance()::checkForUpdates);
|
||||||
|
items.add(checkForUpdateItem);
|
||||||
|
}
|
||||||
items.add(new TextItem(R.string.settings_clear_cache, this::clearImageCache));
|
items.add(new TextItem(R.string.settings_clear_cache, this::clearImageCache));
|
||||||
items.add(new TextItem(R.string.log_out, this::confirmLogOut));
|
items.add(new TextItem(R.string.log_out, this::confirmLogOut));
|
||||||
|
|
||||||
|
@ -326,11 +332,21 @@ public class SettingsFragment extends MastodonToolbarFragment{
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onSelfUpdateStateChanged(SelfUpdateStateChangedEvent ev){
|
public void onSelfUpdateStateChanged(SelfUpdateStateChangedEvent ev){
|
||||||
if(items.get(0) instanceof UpdateItem item){
|
checkForUpdateItem.loading = ev.state == GithubSelfUpdater.UpdateState.CHECKING;
|
||||||
RecyclerView.ViewHolder holder=list.findViewHolderForAdapterPosition(0);
|
if (list.findViewHolderForAdapterPosition(items.indexOf(checkForUpdateItem)) instanceof TextViewHolder tvh) tvh.rebind();
|
||||||
if(holder instanceof UpdateViewHolder uvh){
|
|
||||||
uvh.bind(item);
|
UpdateItem updateItem = null;
|
||||||
}
|
if(items.get(0) instanceof UpdateItem item0) {
|
||||||
|
updateItem = item0;
|
||||||
|
} else if (ev.state != GithubSelfUpdater.UpdateState.CHECKING
|
||||||
|
&& ev.state != GithubSelfUpdater.UpdateState.NO_UPDATE) {
|
||||||
|
updateItem = new UpdateItem();
|
||||||
|
items.add(0, updateItem);
|
||||||
|
list.setAdapter(new SettingsAdapter());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(updateItem != null && list.findViewHolderForAdapterPosition(0) instanceof UpdateViewHolder uvh){
|
||||||
|
uvh.bind(updateItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,10 +414,16 @@ public class SettingsFragment extends MastodonToolbarFragment{
|
||||||
private class TextItem extends Item{
|
private class TextItem extends Item{
|
||||||
private String text;
|
private String text;
|
||||||
private Runnable onClick;
|
private Runnable onClick;
|
||||||
|
private boolean loading;
|
||||||
|
|
||||||
public TextItem(@StringRes int text, Runnable onClick){
|
public TextItem(@StringRes int text, Runnable onClick) {
|
||||||
|
this(text, onClick, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextItem(@StringRes int text, Runnable onClick, boolean loading){
|
||||||
this.text=getString(text);
|
this.text=getString(text);
|
||||||
this.onClick=onClick;
|
this.onClick=onClick;
|
||||||
|
this.loading=loading;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -630,14 +652,18 @@ public class SettingsFragment extends MastodonToolbarFragment{
|
||||||
|
|
||||||
private class TextViewHolder extends BindableViewHolder<TextItem> implements UsableRecyclerView.Clickable{
|
private class TextViewHolder extends BindableViewHolder<TextItem> implements UsableRecyclerView.Clickable{
|
||||||
private final TextView text;
|
private final TextView text;
|
||||||
|
private final ProgressBar progress;
|
||||||
|
|
||||||
public TextViewHolder(){
|
public TextViewHolder(){
|
||||||
super(getActivity(), R.layout.item_settings_text, list);
|
super(getActivity(), R.layout.item_settings_text, list);
|
||||||
text=(TextView) itemView;
|
text = itemView.findViewById(R.id.text);
|
||||||
|
progress = itemView.findViewById(R.id.progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBind(TextItem item){
|
public void onBind(TextItem item){
|
||||||
text.setText(item.text);
|
text.setText(item.text);
|
||||||
|
progress.animate().alpha(item.loading ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -692,8 +718,9 @@ public class SettingsFragment extends MastodonToolbarFragment{
|
||||||
@Override
|
@Override
|
||||||
public void onBind(UpdateItem item){
|
public void onBind(UpdateItem item){
|
||||||
GithubSelfUpdater updater=GithubSelfUpdater.getInstance();
|
GithubSelfUpdater updater=GithubSelfUpdater.getInstance();
|
||||||
GithubSelfUpdater.UpdateInfo info=updater.getUpdateInfo();
|
|
||||||
GithubSelfUpdater.UpdateState state=updater.getState();
|
GithubSelfUpdater.UpdateState state=updater.getState();
|
||||||
|
if (state == GithubSelfUpdater.UpdateState.CHECKING) return;
|
||||||
|
GithubSelfUpdater.UpdateInfo info=updater.getUpdateInfo();
|
||||||
if(state!=GithubSelfUpdater.UpdateState.DOWNLOADED){
|
if(state!=GithubSelfUpdater.UpdateState.DOWNLOADED){
|
||||||
text.setText(getString(R.string.update_available, info.version));
|
text.setText(getString(R.string.update_available, info.version));
|
||||||
button.setText(getString(R.string.download_update, UiUtils.formatFileSize(getActivity(), info.size, false)));
|
button.setText(getString(R.string.download_update, UiUtils.formatFileSize(getActivity(), info.size, false)));
|
||||||
|
|
|
@ -23,6 +23,8 @@ public abstract class GithubSelfUpdater{
|
||||||
return BuildConfig.BUILD_TYPE.equals("githubRelease") || BuildConfig.BUILD_TYPE.equals("debug");
|
return BuildConfig.BUILD_TYPE.equals("githubRelease") || BuildConfig.BUILD_TYPE.equals("debug");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract void checkForUpdates();
|
||||||
|
|
||||||
public abstract void maybeCheckForUpdates();
|
public abstract void maybeCheckForUpdates();
|
||||||
|
|
||||||
public abstract GithubSelfUpdater.UpdateState getState();
|
public abstract GithubSelfUpdater.UpdateState getState();
|
||||||
|
|
|
@ -1,13 +1,30 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:orientation="horizontal"
|
||||||
android:layout_height="48dp"
|
|
||||||
android:paddingLeft="16dp"
|
android:paddingLeft="16dp"
|
||||||
android:paddingRight="16dp"
|
android:paddingRight="16dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="48dp"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:textSize="16sp"
|
android:layoutDirection="locale">
|
||||||
android:textColor="?android:textColorPrimary"
|
<TextView
|
||||||
android:singleLine="true"
|
android:id="@+id/text"
|
||||||
android:ellipsize="end"
|
android:layout_width="match_parent"
|
||||||
tools:text="daffdsa"/>
|
android:layout_weight="1"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:paddingRight="16dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textColor="?android:textColorPrimary"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:ellipsize="end"
|
||||||
|
tools:text="Account settings"/>
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progress"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:alpha="0"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
|
@ -393,4 +393,5 @@
|
||||||
<!-- %s is file size -->
|
<!-- %s is file size -->
|
||||||
<string name="download_update">Download (%s)</string>
|
<string name="download_update">Download (%s)</string>
|
||||||
<string name="install_update">Installieren</string>
|
<string name="install_update">Installieren</string>
|
||||||
|
<string name="check_for_update">Auf Update prüfen</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -402,6 +402,7 @@
|
||||||
<!-- %s is file size -->
|
<!-- %s is file size -->
|
||||||
<string name="download_update">Download (%s)</string>
|
<string name="download_update">Download (%s)</string>
|
||||||
<string name="install_update">Install</string>
|
<string name="install_update">Install</string>
|
||||||
|
<string name="check_for_update">Check for update</string>
|
||||||
<string name="privacy_policy_title">Mastodon and your privacy</string>
|
<string name="privacy_policy_title">Mastodon and your privacy</string>
|
||||||
<string name="privacy_policy_subtitle">Although the Mastodon app does not collect any data, the server you sign up through may have a different policy. Take a minute to review and agree to the Mastodon app privacy policy and your server\'s privacy policy.</string>
|
<string name="privacy_policy_subtitle">Although the Mastodon app does not collect any data, the server you sign up through may have a different policy. Take a minute to review and agree to the Mastodon app privacy policy and your server\'s privacy policy.</string>
|
||||||
<string name="i_agree">I Agree</string>
|
<string name="i_agree">I Agree</string>
|
||||||
|
|
Loading…
Reference in New Issue