Skip to content

Commit

Permalink
Added add from list from widget configure
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb-yun committed Jul 5, 2018
1 parent 8d4f44e commit 1a89377
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 8 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -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'
}
68 changes: 65 additions & 3 deletions app/src/main/java/layout/OverWidgetConfigure.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -35,6 +47,7 @@ public class OverWidgetConfigure extends AppCompatActivity implements OnPreferen
ProgressBar progressBar;
LinearLayout mainContent;
FloatingActionButton fab;
WidgetPrefFragment prefFragment;

public OverWidgetConfigure() {
super();
Expand All @@ -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);
Expand All @@ -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<Profile> 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());
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_configure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
android:id="@+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
<!--<fragment
android:id="@+id/fragment_preference"
android:name="com.cogentworks.overwidget.WidgetPrefFragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content" />-->
</LinearLayout>

<android.support.design.widget.FloatingActionButton
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/menu/menu_configure.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/add_list"
android:title="Add from list" />
</menu>
11 changes: 11 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,15 @@
<item name="android:windowLightStatusBar" tools:targetApi="23">false</item>
</style>

<style name="AppTheme" parent="Theme.AppCompat.Light" />

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ buildscript {

allprojects {
repositories {
jcenter()
google()
jcenter()
mavenCentral()
}
}
Expand Down

0 comments on commit 1a89377

Please sign in to comment.