Skip to content

Commit

Permalink
Merge pull request #6 from maxcanna/fix-ui-glitches
Browse files Browse the repository at this point in the history
Fix UI glitches
  • Loading branch information
maxcanna authored Mar 21, 2021
2 parents 5f27706 + 0871e8e commit b8404a0
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ jobs:
./gradlew getVersionNumber
git config --global user.email "[email protected]"
git config --global user.name "Massimiliano Cannarozzo"
git tag -a $(cat MuzeiWebcam/versionNumber) -m "$(cat MuzeiWebcam/versionNumber)"
git tag -a "v$(cat MuzeiWebcam/versionNumber)" -m "v$(cat MuzeiWebcam/versionNumber)"
git push "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" --tags
2 changes: 1 addition & 1 deletion MuzeiWebcam/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

def versionMajor = 2
def versionMinor = 1
def versionPatch = 0
def versionPatch = 1
def versionBuild = 0

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ public void onLoadRequested(boolean firstTime) {

Context ctx = this.getContext();
String subtitle = SimpleDateFormat.getInstance().format(now);
String title = Utils.getStringValue(ctx, ctx.getString(R.string.preference_key_name));
String title = Utils.getStringValue(ctx, ctx.getString(R.string.preference_key_name), ctx.getString(R.string.app_name));
String url = Utils.getStringValue(ctx, ctx.getString(R.string.preference_key_url));
String viewUrl = url;

if(TextUtils.isEmpty(title)){
title = ctx.getString(R.string.app_name);
}

if(TextUtils.isEmpty(url)){
url = ctx.getString(R.string.source_default_url);
viewUrl = ctx.getString(R.string.source_default_view_url);
title = ctx.getString(R.string.app_name);
subtitle = ctx.getString(R.string.source_default_subtitle);
}

Expand All @@ -54,7 +51,6 @@ public void onLoadRequested(boolean firstTime) {
.byline(subtitle)
.webUri(Uri.parse(viewUrl))
.persistentUri(Uri.parse(url))
.metadata(String.valueOf(now.getTime()))
.build();
setArtwork(artwork);
}
Expand All @@ -63,9 +59,12 @@ public void onLoadRequested(boolean firstTime) {
@Override
public String getDescription() {
final Context ctx = getContext();
String url = Utils.getStringValue(ctx, ctx.getString(R.string.preference_key_url));
return url == null
return TextUtils.isEmpty(Utils.getStringValue(ctx, ctx.getString(R.string.preference_key_url)))
? ctx.getString(R.string.source_default_subtitle)
: null;
: Utils.getStringValue(
ctx,
ctx.getString(R.string.preference_key_name),
ctx.getString(R.string.source_description)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void onResume() {
final String url = getArguments().getString(EXTRA_URL);
if(!TextUtils.isEmpty(url) && Patterns.WEB_URL.matcher(url).matches()){
Utils.storeValue(a, getString(R.string.preference_key_url), url);
updateSubtitles();
} else {
Utils.showToast(a , R.string.error_invalid_url);
}
Expand All @@ -79,7 +80,7 @@ public void onPause() {
public void onViewCreated(@NotNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

TextView mAboutTextView = (TextView) view.findViewById(R.id.about);
TextView mAboutTextView = view.findViewById(R.id.about);
mAboutTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -106,14 +107,11 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
} else if(s.equals(a.getString(R.string.preference_key_url))){
String url = Utils.getStringValue(a, s);
if(TextUtils.isEmpty(url) || !Patterns.WEB_URL.matcher(url).matches()){
if(!TextUtils.isEmpty(url)){
Utils.storeValue(a, s, null);
} else {
Utils.showToast(a, R.string.error_invalid_url);
}
} else {
refresh(a);
Utils.showToast(a, R.string.error_invalid_url);
Utils.storeValue(a, s, null);
}

refresh(a);
}

updateSubtitles();
Expand All @@ -123,8 +121,8 @@ private void refresh(Context c) {
final ProviderClient providerClient = ProviderContract.getProviderClient(c, "net.luxteam.muzeiwebcam");
final Date now = new Date();
final String subtitle = SimpleDateFormat.getInstance().format(now);
final String title = Utils.getStringValue(c, c.getString(R.string.preference_key_name));
final String url = Utils.getStringValue(c, c.getString(R.string.preference_key_url));
final String title = Utils.getStringValue(c, c.getString(R.string.preference_key_name), c.getString(R.string.app_name));
final String url = Utils.getStringValue(c, c.getString(R.string.preference_key_url), c.getString(R.string.source_default_url));
final Uri uri = Uri.parse(url);

providerClient.setArtwork(new Artwork.Builder()
Expand Down
32 changes: 7 additions & 25 deletions MuzeiWebcam/src/main/java/net/luxteam/muzeiwebcam/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,15 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.widget.Toast;

public class Utils {
import androidx.preference.PreferenceManager;

private static Toast t;
public class Utils {

public static void showToast(final Context ctx, int resourceId){
if(ctx == null) return;

final String message = ctx.getString(resourceId);

new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
if (t == null) {
t = Toast.makeText(ctx, message, Toast.LENGTH_SHORT);
} else t.setText(message);

t.show();
}
});
Toast.makeText(ctx, ctx.getString(resourceId), Toast.LENGTH_SHORT).show();
}

public static void storeValue(Context ctx, String name, String value){
Expand All @@ -47,13 +31,11 @@ public static boolean getBooleanValue(Context ctx, String name){
}

public static String getStringValue(Context ctx, String name){
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
return prefs.getString(name, null);
return getStringValue(ctx, name, null);
}

public static boolean isWifiConnected(Context ctx) {
ConnectivityManager connManager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
return mWifi.isConnected();
public static String getStringValue(Context ctx, String name, String defValue){
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
return prefs.getString(name, defValue);
}
}
2 changes: 1 addition & 1 deletion MuzeiWebcam/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string name="preference_title_interval">Aktualisierungsintervall (minuten)</string>
<string name="preference_summary_wifi_only">Laden sie neue bilder nur über WiFi</string>
<string name="preference_summary_grab_url">Teilen sie eine URL als quelle verwenden</string>
<string name="about_credits"><![CDATA[<b>Standardbild</b> von <em>mich</em><br />https://www.flickr.com/photos/maxcanna/<br /><br /><b>Muzei</b> von <em>Roman Nurik</em><br />https://github.com/romannurik/muzei<br /><br /><b>Calligraphy</b> von <em>Christopher Jenkins</em><br />https://github.com/chrisjenx/Calligraphy]]></string>
<string name="about_credits"><![CDATA[<b>Standardbild</b> von <em>mich</em><br />https://www.flickr.com/photos/maxcanna/<br /><br /><b>Muzei</b> von <em>Ian Lake</em><br />https://github.com/muzei/muzei<br /><br /><b>Calligraphy</b> von <em>Christopher Jenkins</em><br />https://github.com/chrisjenx/Calligraphy]]></string>
<string name="about_credits_title">Verdienst</string>
<string name="about_description">Muzei erweiterung erstellt von Massimiliano Cannarozzo um anzeigen webcam-bilder als hintergrundbild.</string>
<string name="about_contacts">Kontakte</string>
Expand Down
2 changes: 1 addition & 1 deletion MuzeiWebcam/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string name="preference_title_interval">Intervalle d\'actualisation (minutes)</string>
<string name="preference_summary_wifi_only">Télécharger de nouvelles images uniquement en WiFi</string>
<string name="preference_summary_grab_url">Partagez une URL pour l\'utiliser</string>
<string name="about_credits"><![CDATA[<b>Image par défaut</b> par <em>me</em><br />https://www.flickr.com/photos/maxcanna/<br /><br /><b>Muzei</b> par <em>Roman Nurik</em><br />https://github.com/romannurik/muzei<br /><br /><b>Calligraphy</b> par <em>Christopher Jenkins</em><br />https://github.com/chrisjenx/Calligraphy]]></string>
<string name="about_credits"><![CDATA[<b>Image par défaut</b> par <em>me</em><br />https://www.flickr.com/photos/maxcanna/<br /><br /><b>Muzei</b> par <em>Ian Lake</em><br />https://github.com/muzei/muzei<br /><br /><b>Calligraphy</b> par <em>Christopher Jenkins</em><br />https://github.com/chrisjenx/Calligraphy]]></string>
<string name="about_credits_title">Reconnaissances</string>
<string name="about_description">Extension pour Muzei créé par Massimiliano Cannarozzo pour montrer images de webcam comme fond d\'écran.</string>
<string name="about_contacts">Contacts</string>
Expand Down
2 changes: 1 addition & 1 deletion MuzeiWebcam/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string name="preference_title_interval">Intervallo aggiornamento (minuti)</string>
<string name="preference_summary_wifi_only">Scarica nuove immagini solo in WiFi</string>
<string name="preference_summary_grab_url">Condividi un\'URL per usarla come fonte</string>
<string name="about_credits"><![CDATA[<b>Immagine predefinita</b> <em>mia</em><br />https://www.flickr.com/photos/maxcanna/<br /><br /><b>Muzei</b> di <em>Roman Nurik</em><br />https://github.com/romannurik/muzei<br /><br /><b>Calligraphy</b> di <em>Christopher Jenkins</em><br />https://github.com/chrisjenx/Calligraphy]]></string>
<string name="about_credits"><![CDATA[<b>Immagine predefinita</b> <em>mia</em><br />https://www.flickr.com/photos/maxcanna/<br /><br /><b>Muzei</b> di <em>Ian Lake</em><br />https://github.com/muzei/muzei<br /><br /><b>Calligraphy</b> di <em>Christopher Jenkins</em><br />https://github.com/chrisjenx/Calligraphy]]></string>
<string name="about_credits_title">Crediti</string>
<string name="about_description">Estensione per il Live Wallpaper Muzei creata da Massimiliano Cannarozzo per visualizzare immagini di una webcam come sfondo.</string>
<string name="about_contacts">Contatti</string>
Expand Down
2 changes: 1 addition & 1 deletion MuzeiWebcam/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string name="preference_title_interval">Intervalo de atualização (minutos)</string>
<string name="preference_summary_wifi_only">Descarregue novas imagens somente via Wi-Fi</string>
<string name="preference_summary_grab_url">Compartilhar uma URL para usá-lo como fonte</string>
<string name="about_credits"><![CDATA[<b>Imagem predefinida</b> por <em>me</em><br />https://www.flickr.com/photos/maxcanna/<br /><br /><b>Muzei</b> por <em>Roman Nurik</em><br />https://github.com/romannurik/muzei<br /><br /><b>Calligraphy</b> por <em>Christopher Jenkins</em><br />https://github.com/chrisjenx/Calligraphy]]></string>
<string name="about_credits"><![CDATA[<b>Imagem predefinida</b> por <em>me</em><br />https://www.flickr.com/photos/maxcanna/<br /><br /><b>Muzei</b> por <em>Ian Lake</em><br />https://github.com/muzei/muzei<br /><br /><b>Calligraphy</b> por <em>Christopher Jenkins</em><br />https://github.com/chrisjenx/Calligraphy]]></string>
<string name="about_credits_title">Créditos</string>
<string name="about_description">Extensão para Muzei criado por Massimiliano Cannarozzo para mostrar imagens de webcams como papel de parede.</string>
<string name="about_contacts">Contactos</string>
Expand Down
3 changes: 1 addition & 2 deletions MuzeiWebcam/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
<string name="preference_title_interval">Refresh interval (minutes)</string>
<string name="preference_summary_wifi_only">Download new images only on WiFi</string>
<string name="preference_summary_grab_url">Share an URL to use it as source</string>
<string name="about_credits"><![CDATA[<b>Default image</b> by <em>me</em><br />https://www.flickr.com/photos/maxcanna/<br /><br /><b>Muzei</b> by <em>Roman Nurik</em><br />https://github.com/romannurik/muzei<br /><br /><b>Calligraphy</b> by <em>Christopher Jenkins</em><br />https://github.com/chrisjenx/Calligraphy]]></string>
<string name="about_credits"><![CDATA[<b>Default image</b> by <em>me</em><br />https://www.flickr.com/photos/maxcanna/<br /><br /><b>Muzei</b> by <em>Ian Lake</em><br />https://github.com/muzei/muzei<br /><br /><b>Calligraphy</b> by <em>Christopher Jenkins</em><br />https://github.com/chrisjenx/Calligraphy]]></string>
<string name="about_credits_title">Credits</string>
<string name="about_description">Muzei Live Wallpaper extension created by Massimiliano Cannarozzo to show webcam imagery as wallpaper.</string>
<string name="about_contacts">Contacts</string>
<string translatable="false" name="content_description_twitter">Twitter</string>
<string translatable="false" name="content_description_facebook">Facebook</string>
<string translatable="false" name="content_description_gplus">Google+</string>
<string translatable="false" name="content_description_gplay">Google Play</string>
<string translatable="false" name="content_description_github">GitHub</string>
</resources>

0 comments on commit b8404a0

Please sign in to comment.