diff --git a/app/build.gradle b/app/build.gradle index 4b73dc4..3af7b07 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,7 +24,7 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.android.support.constraint:constraint-layout:1.1.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.2' implementation 'com.android.support:support-v4:27.1.1' implementation 'com.android.support:support-vector-drawable:27.1.1' androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { @@ -34,10 +34,12 @@ dependencies { implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:support-compat:27.1.1' implementation 'com.android.support:design:27.1.1' + implementation 'com.google.code.gson:gson:2.8.4' testImplementation 'junit:junit:4.12' implementation 'com.github.bumptech.glide:glide:4.7.1' annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1' - //implementation 'com.github.woxthebox:draglistview:1.6.1' + implementation 'com.android.support:recyclerview-v7:27.1.1' + implementation 'com.github.woxthebox:draglistview:1.6.1' } diff --git a/app/src/main/java/layout/OverWidgetConfigure.java b/app/src/main/java/layout/OverWidgetConfigure.java index 4bc6bdf..a61dced 100644 --- a/app/src/main/java/layout/OverWidgetConfigure.java +++ b/app/src/main/java/layout/OverWidgetConfigure.java @@ -2,8 +2,12 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; +import android.app.AlertDialog; +import android.app.FragmentManager; +import android.app.FragmentTransaction; import android.appwidget.AppWidgetManager; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; @@ -12,20 +16,28 @@ import android.preference.PreferenceManager; import android.support.design.widget.FloatingActionButton; import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.widget.LinearLayout; import android.widget.ProgressBar; import com.cogentworks.overwidget.CreateWidget; +import com.cogentworks.overwidget.Profile; import com.cogentworks.overwidget.R; +import com.cogentworks.overwidget.SQLHelper; import com.cogentworks.overwidget.SettingsActivity; +import com.cogentworks.overwidget.WidgetPrefFragment; import com.cogentworks.overwidget.WidgetUtils; +import java.util.ArrayList; + /** * The configuration screen for the {@link OverWidgetProvider OverWidgetProvider} AppWidget. */ -public class OverWidgetConfigure extends AppCompatActivity implements OnPreferenceChangeListener{ +public class OverWidgetConfigure extends AppCompatActivity implements OnPreferenceChangeListener { private static final String TAG = "OverWidgetConfigure"; public static final String PREFS_NAME = "layout.OverWidgetProvider"; @@ -35,6 +47,7 @@ public class OverWidgetConfigure extends AppCompatActivity implements OnPreferen ProgressBar progressBar; LinearLayout mainContent; FloatingActionButton fab; + WidgetPrefFragment prefFragment; public OverWidgetConfigure() { super(); @@ -49,13 +62,19 @@ protected void onCreate(Bundle savedInstanceState) { sp.edit().remove("theme").apply(); sp.edit().remove("interval").apply(); - boolean useDarkTheme = PreferenceManager.getDefaultSharedPreferences(getBaseContext()) - .getBoolean(SettingsActivity.PREF_DARK_THEME, false); + boolean useDarkTheme = sp.getBoolean(SettingsActivity.PREF_DARK_THEME, false); if (useDarkTheme) setTheme(R.style.Blackwatch); super.onCreate(savedInstanceState); + // Display the fragment as the main content. + FragmentManager mFragmentManager = getFragmentManager(); + FragmentTransaction mFragmentTransaction = mFragmentManager.beginTransaction(); + prefFragment = new WidgetPrefFragment(); + mFragmentTransaction.replace(R.id.layout_main, prefFragment); + mFragmentTransaction.commit(); + setContentView(R.layout.activity_configure); mainContent = findViewById(R.id.layout_main); progressBar = findViewById(R.id.progress_bar); @@ -75,6 +94,49 @@ protected void onCreate(Bundle savedInstanceState) { } } + public boolean onCreateOptionsMenu(Menu menu) { + + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.menu_configure, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + + switch (item.getItemId()) { + case R.id.add_list: + final OverWidgetConfigure activity = this; + SQLHelper dbHelper = new SQLHelper(this); + final ArrayList profiles = dbHelper.getList(); + CharSequence[] names = new CharSequence[profiles.size()]; + for (int i = 0; i < profiles.size(); i++) + names[i] = profiles.get(i).BattleTag; + final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); + AlertDialog dialog = new AlertDialog.Builder(this) + .setTitle("Add from List") + .setItems(names, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + SharedPreferences.Editor editor = settings.edit(); + editor.putString("username", profiles.get(which).BattleTag); + editor.putString("platform", profiles.get(which).Platform); + editor.putString("region", profiles.get(which).Region); + prefFragment.findPreference("username").setSummary(profiles.get(which).BattleTag); + prefFragment.findPreference("platform").setSummary(profiles.get(which).Platform); + prefFragment.findPreference("region").setSummary(profiles.get(which).Region); + editor.apply(); + } + }) + .setNegativeButton("Cancel", null) + .create(); + dialog.show(); + + return true; + default: + return false; + } + } + @Override public boolean onPreferenceChange(Preference preference, Object newValue) { preference.setSummary(newValue.toString()); diff --git a/app/src/main/res/layout/activity_configure.xml b/app/src/main/res/layout/activity_configure.xml index 5c7cd1e..e60bf9b 100644 --- a/app/src/main/res/layout/activity_configure.xml +++ b/app/src/main/res/layout/activity_configure.xml @@ -16,11 +16,11 @@ android:id="@+id/layout_main" android:layout_width="match_parent" android:layout_height="match_parent"> - + android:layout_height="wrap_content" />--> + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 0b51ff6..ad3a846 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -17,4 +17,15 @@ false + + +