Skip to content

Commit

Permalink
Merge pull request forrestguice#762 from forrestguice/export
Browse files Browse the repository at this point in the history
backup all settings
  • Loading branch information
forrestguice authored Jan 29, 2024
2 parents dda197b + 7a65594 commit e4f7f88
Show file tree
Hide file tree
Showing 63 changed files with 5,195 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
Copyright (C) 2024 Forrest Guice
This file is part of SuntimesWidget.
SuntimesWidget 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.
SuntimesWidget 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 SuntimesWidget. If not, see <http://www.gnu.org/licenses/>.
*/

package com.forrestguice.suntimeswidget.settings;

import android.content.ContentValues;

import org.junit.Test;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertNotEquals;

public class WidgetSettingsMetadataTest
{
private static final String className = "class0";
private static final int versionCode = 100;
private static final int category = 200;
private static final int minWidth = 300;
private static final int minHeight = 400;
private static final int maxWidth = 500;
private static final int maxHeight = 600;

private static final String className1 = "class1";
private static final int versionCode1 = 1000;
private static final int category1 = 1200;
private static final int minWidth1 = 1300;
private static final int minHeight1 = 1400;
private static final int maxWidth1 = 1500;
private static final int maxHeight1 = 1600;


protected ContentValues createContentValues0(Long appWidgetId0)
{
ContentValues values0 = new ContentValues();
values0.put(WidgetSettings.PREF_PREFIX_KEY + appWidgetId0 + WidgetSettingsMetadata.PREF_PREFIX_KEY_META + WidgetSettingsMetadata.PREF_KEY_META_CLASSNAME, className);
values0.put(WidgetSettings.PREF_PREFIX_KEY + appWidgetId0 + WidgetSettingsMetadata.PREF_PREFIX_KEY_META + WidgetSettingsMetadata.PREF_KEY_META_VERSIONCODE, versionCode);
values0.put(WidgetSettings.PREF_PREFIX_KEY + appWidgetId0 + WidgetSettingsMetadata.PREF_PREFIX_KEY_META + WidgetSettingsMetadata.PREF_KEY_META_CATEGORY, category);
values0.put(WidgetSettings.PREF_PREFIX_KEY + appWidgetId0 + WidgetSettingsMetadata.PREF_PREFIX_KEY_META + WidgetSettingsMetadata.PREF_KEY_META_WIDTH_MIN, minWidth);
values0.put(WidgetSettings.PREF_PREFIX_KEY + appWidgetId0 + WidgetSettingsMetadata.PREF_PREFIX_KEY_META + WidgetSettingsMetadata.PREF_KEY_META_HEIGHT_MIN, minHeight);
values0.put(WidgetSettings.PREF_PREFIX_KEY + appWidgetId0 + WidgetSettingsMetadata.PREF_PREFIX_KEY_META + WidgetSettingsMetadata.PREF_KEY_META_WIDTH_MAX, maxWidth);
values0.put(WidgetSettings.PREF_PREFIX_KEY + appWidgetId0 + WidgetSettingsMetadata.PREF_PREFIX_KEY_META + WidgetSettingsMetadata.PREF_KEY_META_HEIGHT_MAX, maxHeight);
return values0;
}

@Test
public void test_WidgetMetadata_getMetaDataFromValues()
{
long appWidgetId0 = 100;
ContentValues values0 = createContentValues0(appWidgetId0);
WidgetSettingsMetadata.WidgetMetadata d0 = WidgetSettingsMetadata.WidgetMetadata.getMetaDataFromValues(values0, appWidgetId0);
assertEquals(d0.getWidgetClassName(), className);
assertEquals(d0.getVersionCode(), versionCode);
assertEquals(d0.getCategory(), category);
assertEquals(d0.getMinDimensions()[0], minWidth);
assertEquals(d0.getMinDimensions()[1], minHeight);
assertEquals(d0.getMaxDimensions()[0], maxWidth);
assertEquals(d0.getMaxDimensions()[1], maxHeight);

WidgetSettingsMetadata.WidgetMetadata d1 = WidgetSettingsMetadata.WidgetMetadata.getMetaDataFromValues(values0);
assertEquals(d1.getWidgetClassName(), className);
assertEquals(d1.getVersionCode(), versionCode);
assertEquals(d1.getCategory(), category);
assertEquals(d1.getMinDimensions()[0], minWidth);
assertEquals(d1.getMinDimensions()[1], minHeight);
assertEquals(d1.getMaxDimensions()[0], maxWidth);
assertEquals(d1.getMaxDimensions()[1], maxHeight);
}

@Test
public void test_WidgetMetadata_findAppWidgetIdFromFirstKey()
{
Long appWidgetId0 = 100L;
ContentValues values0 = createContentValues0(appWidgetId0);
Long appWidgetId1 = WidgetSettingsImportTask.findAppWidgetIdFromFirstKey(values0);
assertNotNull(appWidgetId1);
assertEquals(appWidgetId1, appWidgetId0);

ContentValues values2 = new ContentValues();
Long appWidgetId3 = WidgetSettingsImportTask.findAppWidgetIdFromFirstKey(values2);
assertNull(appWidgetId3);
}

@Test
public void test_WidgetMetadata_replaceKeyPrefix()
{
Long appWidgetId0 = 100L;
ContentValues values0 = createContentValues0(appWidgetId0);
String key0 = WidgetSettings.PREF_PREFIX_KEY + appWidgetId0 + WidgetSettingsMetadata.PREF_PREFIX_KEY_META + "testKey";
String value0 = "testValue";
values0.put(key0, value0);

int appWidgetId1 = 200;
ContentValues values1 = WidgetSettingsImportTask.replaceKeyPrefix(values0, appWidgetId1);
String key1 = WidgetSettings.PREF_PREFIX_KEY + appWidgetId1 + WidgetSettingsMetadata.PREF_PREFIX_KEY_META + "testKey";
assertNotNull(values1);
assertTrue(values1.containsKey(key1));
assertEquals(values1.get(key1), value0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ public void onClick(View v) {
supportView.setText(SuntimesUtils.fromHtml(context.getString(R.string.app_support_url)));
}

TextView donateView = (TextView) dialogContent.findViewById(R.id.txt_donate_url);
if (donateView != null) {
donateView.setMovementMethod(LinkMovementMethod.getInstance());
donateView.setText(SuntimesUtils.fromHtml(context.getString(R.string.app_donate_url, context.getString(R.string.app_name))));
}

TextView legalView1 = (TextView) dialogContent.findViewById(R.id.txt_about_legal1);
if (legalView1 != null) {
legalView1.setMovementMethod(LinkMovementMethod.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import com.forrestguice.suntimeswidget.settings.WidgetSettings;
import com.forrestguice.suntimeswidget.themes.WidgetThemeConfigActivity;

import static com.forrestguice.suntimeswidget.themes.WidgetThemeListActivity.PICK_THEME_REQUEST;

/**
* Clock widget config activity.
*/
Expand All @@ -39,6 +37,11 @@ public ClockWidget0ConfigActivity()
super();
}

@Override
protected Class getWidgetClass() {
return ClockWidget0.class;
}

@Override
protected void initViews( Context context )
{
Expand Down Expand Up @@ -73,7 +76,7 @@ protected void initViews( Context context )
@Override
protected void updateWidgets(Context context, int[] appWidgetIds)
{
Intent updateIntent = new Intent(context, ClockWidget0.class);
Intent updateIntent = new Intent(context, getWidgetClass());
updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
sendBroadcast(updateIntent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public ClockWidget0ConfigActivity_3x1()
super();
}

@Override
protected Class getWidgetClass() {
return ClockWidget0_3x1.class;
}

@Override
protected void initViews( Context context ) {
super.initViews(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public MoonWidget0ConfigActivity()
super();
}

@Override
protected Class getWidgetClass() {
return MoonWidget0.class;
}

@Override
protected void initViews( Context context )
{
Expand All @@ -60,7 +65,7 @@ protected void initViews( Context context )
@Override
protected void updateWidgets(Context context, int[] appWidgetIds)
{
Intent updateIntent = new Intent(context, MoonWidget0.class);
Intent updateIntent = new Intent(context, getWidgetClass());
updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
sendBroadcast(updateIntent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public MoonWidget0ConfigActivity_2x1()
super();
}

@Override
protected Class getWidgetClass() {
return MoonWidget0_2x1.class;
}

@Override
protected void initViews( Context context )
{
Expand All @@ -46,7 +51,7 @@ protected void initViews( Context context )
@Override
protected void updateWidgets(Context context, int[] appWidgetIds)
{
Intent updateIntent = new Intent(context, MoonWidget0_2x1.class);
Intent updateIntent = new Intent(context, getWidgetClass());
updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
sendBroadcast(updateIntent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public MoonWidget0ConfigActivity_3x1()
super();
}

@Override
protected Class getWidgetClass() {
return MoonWidget0_3x1.class;
}

@Override
protected void initViews( Context context )
{
Expand All @@ -50,7 +55,7 @@ protected void initViews( Context context )
@Override
protected void updateWidgets(Context context, int[] appWidgetIds)
{
Intent updateIntent = new Intent(context, MoonWidget0_3x1.class);
Intent updateIntent = new Intent(context, getWidgetClass());
updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
sendBroadcast(updateIntent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public MoonWidget0ConfigActivity_3x2()
super();
}
@Override
protected Class getWidgetClass() {
return MoonWidget0_3x2.class;
}
@Override
protected void initViews( Context context )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public SolsticeWidget0ConfigActivity()
super();
}

@Override
protected Class getWidgetClass() {
return SolsticeWidget0.class;
}

@Override
protected void initViews( Context context )
{
Expand All @@ -72,7 +77,7 @@ protected void initViews( Context context )
@Override
protected void updateWidgets(Context context, int[] appWidgetIds)
{
Intent updateIntent = new Intent(context, SolsticeWidget0.class);
Intent updateIntent = new Intent(context, getWidgetClass());
updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
sendBroadcast(updateIntent);
Expand Down
Loading

0 comments on commit e4f7f88

Please sign in to comment.