Some offline fixes
This commit is contained in:
parent
7aab6fbba9
commit
b2f1bf2817
|
@ -44,7 +44,6 @@ import app.fedilab.fedilabtube.client.APIResponse;
|
||||||
import app.fedilab.fedilabtube.client.entities.Instance;
|
import app.fedilab.fedilabtube.client.entities.Instance;
|
||||||
import app.fedilab.fedilabtube.client.entities.InstanceParams;
|
import app.fedilab.fedilabtube.client.entities.InstanceParams;
|
||||||
import app.fedilab.fedilabtube.drawer.InstanceAdapter;
|
import app.fedilab.fedilabtube.drawer.InstanceAdapter;
|
||||||
import app.fedilab.fedilabtube.helper.Helper;
|
|
||||||
import app.fedilab.fedilabtube.helper.RoundedBackgroundSpan;
|
import app.fedilab.fedilabtube.helper.RoundedBackgroundSpan;
|
||||||
import app.fedilab.fedilabtube.viewmodel.InstancesVM;
|
import app.fedilab.fedilabtube.viewmodel.InstancesVM;
|
||||||
import es.dmoral.toasty.Toasty;
|
import es.dmoral.toasty.Toasty;
|
||||||
|
@ -110,7 +109,7 @@ public class InstancePickerActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (peertubeInformation != null && peertubeInformation.getLanguages() != null) {
|
||||||
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
|
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
|
||||||
checkedItemsLanguage = new boolean[languages.size()];
|
checkedItemsLanguage = new boolean[languages.size()];
|
||||||
itemsLabelLanguage = new String[languages.size()];
|
itemsLabelLanguage = new String[languages.size()];
|
||||||
|
@ -145,8 +144,8 @@ public class InstancePickerActivity extends AppCompatActivity {
|
||||||
stringBuilder.append(between);
|
stringBuilder.append(between);
|
||||||
List<String> langs = new ArrayList<>();
|
List<String> langs = new ArrayList<>();
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for(boolean itemcheked: checkedItemsLanguage){
|
for (boolean itemcheked : checkedItemsLanguage) {
|
||||||
if( itemcheked) {
|
if (itemcheked) {
|
||||||
langs.add(itemsKeyLanguage[j]);
|
langs.add(itemsKeyLanguage[j]);
|
||||||
String lang = itemsLabelLanguage[j];
|
String lang = itemsLabelLanguage[j];
|
||||||
if (lang != null && lang.trim().toLowerCase().compareTo("null") != 0) {
|
if (lang != null && lang.trim().toLowerCase().compareTo("null") != 0) {
|
||||||
|
@ -175,7 +174,9 @@ public class InstancePickerActivity extends AppCompatActivity {
|
||||||
alertDialog.setTitle(getString(R.string.pickup_languages));
|
alertDialog.setTitle(getString(R.string.pickup_languages));
|
||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (peertubeInformation != null && peertubeInformation.getLanguages() != null) {
|
||||||
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
|
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
|
||||||
checkedItemsCategory = new boolean[categories.size()];
|
checkedItemsCategory = new boolean[categories.size()];
|
||||||
itemsLabelCategory = new String[categories.size()];
|
itemsLabelCategory = new String[categories.size()];
|
||||||
|
@ -208,8 +209,8 @@ public class InstancePickerActivity extends AppCompatActivity {
|
||||||
String between = "";
|
String between = "";
|
||||||
stringBuilder.append(between);
|
stringBuilder.append(between);
|
||||||
List<Integer> cats = new ArrayList<>();
|
List<Integer> cats = new ArrayList<>();
|
||||||
for(boolean itemcheked: checkedItemsCategory){
|
for (boolean itemcheked : checkedItemsCategory) {
|
||||||
if( itemcheked) {
|
if (itemcheked) {
|
||||||
cats.add(itemsKeyCategory[j]);
|
cats.add(itemsKeyCategory[j]);
|
||||||
String cat = itemsLabelCategory[j];
|
String cat = itemsLabelCategory[j];
|
||||||
if (cat != null && cat.trim().toLowerCase().compareTo("null") != 0) {
|
if (cat != null && cat.trim().toLowerCase().compareTo("null") != 0) {
|
||||||
|
@ -238,6 +239,8 @@ public class InstancePickerActivity extends AppCompatActivity {
|
||||||
alertDialog.setTitle(getString(R.string.pickup_categories));
|
alertDialog.setTitle(getString(R.string.pickup_categories));
|
||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
mainLoader.setVisibility(View.VISIBLE);
|
mainLoader.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,7 @@ public class InstanceAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||||
|
|
||||||
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
||||||
String between = "";
|
String between = "";
|
||||||
|
if (peertubeInformation != null && peertubeInformation.getCategories() != null) {
|
||||||
LinkedHashMap<Integer, String> info_cat = new LinkedHashMap<>(peertubeInformation.getCategories());
|
LinkedHashMap<Integer, String> info_cat = new LinkedHashMap<>(peertubeInformation.getCategories());
|
||||||
if (instance.getCategories() != null && instance.getCategories().size() > 0 && instance.getSpannableStringBuilder() == null) {
|
if (instance.getCategories() != null && instance.getCategories().size() > 0 && instance.getSpannableStringBuilder() == null) {
|
||||||
Iterator<Map.Entry<Integer, Integer>> it = instance.getCategories().entrySet().iterator();
|
Iterator<Map.Entry<Integer, Integer>> it = instance.getCategories().entrySet().iterator();
|
||||||
|
@ -97,10 +98,12 @@ public class InstanceAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||||
}
|
}
|
||||||
instance.setSpannableStringBuilder(stringBuilder);
|
instance.setSpannableStringBuilder(stringBuilder);
|
||||||
}
|
}
|
||||||
if( instance.getSpannableStringBuilder() != null) {
|
}
|
||||||
|
if (instance.getSpannableStringBuilder() != null) {
|
||||||
holder.tags.setText(instance.getSpannableStringBuilder());
|
holder.tags.setText(instance.getSpannableStringBuilder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (peertubeInformation != null && peertubeInformation.getLanguages() != null) {
|
||||||
LinkedHashMap<String, String> info_lang = new LinkedHashMap<>(peertubeInformation.getLanguages());
|
LinkedHashMap<String, String> info_lang = new LinkedHashMap<>(peertubeInformation.getLanguages());
|
||||||
StringBuilder languages = new StringBuilder();
|
StringBuilder languages = new StringBuilder();
|
||||||
if (instance.getLanguages() != null && instance.getLanguages().size() > 0) {
|
if (instance.getLanguages() != null && instance.getLanguages().size() > 0) {
|
||||||
|
@ -111,14 +114,13 @@ public class InstanceAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (languages.toString().trim().length() == 0) {
|
if (languages.toString().trim().length() == 0) {
|
||||||
holder.languages.setVisibility(View.GONE);
|
holder.languages.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
holder.languages.setText(languages);
|
holder.languages.setText(languages);
|
||||||
holder.languages.setVisibility(View.VISIBLE);
|
holder.languages.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (instance.getDefaultNSFWPolicy().compareTo("do_not_list") != 0) {
|
if (instance.getDefaultNSFWPolicy().compareTo("do_not_list") != 0) {
|
||||||
holder.sensitive_content.setText(context.getString(R.string.sensitive_content, instance.getDefaultNSFWPolicy()));
|
holder.sensitive_content.setText(context.getString(R.string.sensitive_content, instance.getDefaultNSFWPolicy()));
|
||||||
holder.sensitive_content.setVisibility(View.VISIBLE);
|
holder.sensitive_content.setVisibility(View.VISIBLE);
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
package app.fedilab.fedilabtube.helper;
|
||||||
|
/* Copyright 2020 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of TubeLab
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Original work from https://stackoverflow.com/a/25873554
|
||||||
|
*/
|
||||||
|
public class NetworkStateReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
protected Set<NetworkStateReceiverListener> listeners;
|
||||||
|
protected Boolean connected;
|
||||||
|
|
||||||
|
public NetworkStateReceiver() {
|
||||||
|
listeners = new HashSet<>();
|
||||||
|
connected = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (intent == null || intent.getExtras() == null)
|
||||||
|
return;
|
||||||
|
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
assert manager != null;
|
||||||
|
NetworkInfo ni = manager.getActiveNetworkInfo();
|
||||||
|
if (ni != null && ni.getState() == NetworkInfo.State.CONNECTED) {
|
||||||
|
connected = true;
|
||||||
|
} else if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, Boolean.FALSE)) {
|
||||||
|
connected = false;
|
||||||
|
}
|
||||||
|
notifyStateToAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void notifyStateToAll() {
|
||||||
|
for (NetworkStateReceiverListener listener : listeners)
|
||||||
|
notifyState(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifyState(NetworkStateReceiverListener listener) {
|
||||||
|
if (connected == null || listener == null)
|
||||||
|
return;
|
||||||
|
if (connected)
|
||||||
|
listener.networkAvailable();
|
||||||
|
else
|
||||||
|
listener.networkUnavailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addListener(NetworkStateReceiverListener l) {
|
||||||
|
listeners.add(l);
|
||||||
|
notifyState(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeListener(NetworkStateReceiverListener l) {
|
||||||
|
listeners.remove(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface NetworkStateReceiverListener {
|
||||||
|
void networkAvailable();
|
||||||
|
|
||||||
|
void networkUnavailable();
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ package app.fedilab.fedilabtube.services;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
|
||||||
|
@ -29,13 +30,25 @@ import app.fedilab.fedilabtube.R;
|
||||||
import app.fedilab.fedilabtube.client.HttpsConnection;
|
import app.fedilab.fedilabtube.client.HttpsConnection;
|
||||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||||
import app.fedilab.fedilabtube.client.entities.PeertubeInformation;
|
import app.fedilab.fedilabtube.client.entities.PeertubeInformation;
|
||||||
|
import app.fedilab.fedilabtube.helper.NetworkStateReceiver;
|
||||||
|
|
||||||
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
|
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
|
||||||
|
|
||||||
|
|
||||||
public class RetrieveInfoService extends Service {
|
public class RetrieveInfoService extends Service implements NetworkStateReceiver.NetworkStateReceiverListener {
|
||||||
|
|
||||||
static String NOTIFICATION_CHANNEL_ID = "update_info";
|
static String NOTIFICATION_CHANNEL_ID = "update_info";
|
||||||
|
private NetworkStateReceiver networkStateReceiver;
|
||||||
|
|
||||||
|
|
||||||
|
public void onCreate() {
|
||||||
|
super.onCreate();
|
||||||
|
networkStateReceiver = new NetworkStateReceiver();
|
||||||
|
networkStateReceiver.addListener(this);
|
||||||
|
registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
@ -92,4 +105,44 @@ public class RetrieveInfoService extends Service {
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
if (networkStateReceiver != null) {
|
||||||
|
networkStateReceiver.removeListener(this);
|
||||||
|
unregisterReceiver(networkStateReceiver);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void networkAvailable() {
|
||||||
|
Thread thread = new Thread() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
peertubeInformation = new PeertubeInformation();
|
||||||
|
peertubeInformation.setCategories(new LinkedHashMap<>());
|
||||||
|
peertubeInformation.setLanguages(new LinkedHashMap<>());
|
||||||
|
peertubeInformation.setLicences(new LinkedHashMap<>());
|
||||||
|
peertubeInformation.setPrivacies(new LinkedHashMap<>());
|
||||||
|
peertubeInformation.setPlaylistPrivacies(new LinkedHashMap<>());
|
||||||
|
peertubeInformation.setTranslations(new LinkedHashMap<>());
|
||||||
|
try {
|
||||||
|
peertubeInformation = new PeertubeAPI(RetrieveInfoService.this).getPeertubeInformation();
|
||||||
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
stopForeground(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void networkUnavailable() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue