Skip to content

Commit

Permalink
Fix stupid Fragment handling from Android-Studio-Prefab "NavigationDr…
Browse files Browse the repository at this point in the history
…awerActivity" (complete rewrite) (Still some unnecessary classes and files left to clean up) (srsly: who creates the AS-Prefabs?!?!)

Fix broken schedule (due to broken fragment handling)
Add material design
Add support for multiple bots
Enhanced dynamic coloring of controls
Brake support for coloring on activities
Add nice images for navigationdrawer
Lots of code optimizations
  • Loading branch information
rampage128 committed Oct 8, 2015
1 parent 861844c commit b9bb44f
Show file tree
Hide file tree
Showing 105 changed files with 1,105 additions and 262 deletions.
11 changes: 11 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
wearApp project(':wear')
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
//compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.pes.materialcolorpicker:library:1.0.+'
}
2 changes: 2 additions & 0 deletions mobile/mobile.iml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/mediarouter-v7/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-ads/8.1.0/jars" />
Expand Down Expand Up @@ -135,6 +136,7 @@
<orderEntry type="library" exported="" name="play-services-ads-8.1.0" level="project" />
<orderEntry type="library" exported="" name="play-services-appstate-8.1.0" level="project" />
<orderEntry type="library" exported="" name="play-services-gcm-8.1.0" level="project" />
<orderEntry type="library" exported="" name="design-23.0.1" level="project" />
<orderEntry type="library" exported="" name="play-services-safetynet-8.1.0" level="project" />
<orderEntry type="library" exported="" name="play-services-games-8.1.0" level="project" />
<orderEntry type="library" exported="" name="play-services-wallet-8.1.0" level="project" />
Expand Down
13 changes: 11 additions & 2 deletions mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme.NoActionBar" >
android:supportsRtl="true"
<activity
android:name=".MainActivity"
android:label="@string/app_name">
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -26,6 +27,14 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="de.jlab.android.hombot.MainActivity" />
</activity>
<activity
android:name=".BotManagerActivity"
android:label="@string/title_activity_bot_manager"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="de.jlab.android.hombot.MainActivity" />
</activity>
</application>

</manifest>
138 changes: 138 additions & 0 deletions mobile/src/main/java/de/jlab/android/hombot/BotManagerActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package de.jlab.android.hombot;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.CursorAdapter;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import de.jlab.android.hombot.data.BotCursorAdapter;
import de.jlab.android.hombot.data.EditBotDialog;
import de.jlab.android.hombot.data.HombotDataContract;
import de.jlab.android.hombot.data.HombotDataOpenHelper;

public class BotManagerActivity extends AppCompatActivity implements EditBotDialog.BotEditDialogListener {

private BotCursorAdapter mBotAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bot_manager);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
/*
ContentValues values = new ContentValues();
values.put(HombotDataContract.BotEntry.COLUMN_NAME_NAME, "Testbot");
values.put(HombotDataContract.BotEntry.COLUMN_NAME_ADDRESS, "192.168.0.30:6260");
db.insertOrThrow(HombotDataContract.BotEntry.TABLE_NAME, null, values);
*/
Snackbar.make(view, "Testbot added", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
showEditDialog(null, null, -1);
}
});


final ListView botList = (ListView) findViewById(R.id.bot_list);
mBotAdapter = new BotCursorAdapter(this, null);
loadBots();
botList.setAdapter(mBotAdapter);

mBotAdapter.setSecondaryItemClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = botList.getPositionForView(v);
Cursor cursor = mBotAdapter.getCursor();
cursor.moveToPosition(position);
long botId = cursor.getLong(cursor.getColumnIndex(HombotDataContract.BotEntry._ID));

deleteBot(botId);
}
});

botList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor cursor = ((CursorAdapter)parent.getAdapter()).getCursor();
cursor.moveToPosition(position);
long botId = cursor.getLong(cursor.getColumnIndex(HombotDataContract.BotEntry._ID));
String name = cursor.getString(cursor.getColumnIndex(HombotDataContract.BotEntry.COLUMN_NAME_NAME));
String address = cursor.getString(cursor.getColumnIndex(HombotDataContract.BotEntry.COLUMN_NAME_ADDRESS));

showEditDialog(name, address, botId);
}
});


}

private void deleteBot(long id) {
HombotDataOpenHelper dataHelper = new HombotDataOpenHelper(this);
SQLiteDatabase db = dataHelper.getWritableDatabase();

db.delete(HombotDataContract.BotEntry.TABLE_NAME, HombotDataContract.BotEntry._ID + "=" + id, null);

dataHelper.close();
loadBots();
}

private void showEditDialog(String name, String address, long id) {
FragmentManager fm = getSupportFragmentManager();
EditBotDialog editBotDialog = EditBotDialog.newInstance(name, address, id);
editBotDialog.show(fm, "fragment_edit_bot");
}

private void loadBots() {
HombotDataOpenHelper dataHelper = new HombotDataOpenHelper(this);
final SQLiteDatabase db = dataHelper.getReadableDatabase();
Cursor botCursor = db.query(HombotDataContract.BotEntry.TABLE_NAME, new String[]{HombotDataContract.BotEntry._ID, HombotDataContract.BotEntry.COLUMN_NAME_NAME, HombotDataContract.BotEntry.COLUMN_NAME_ADDRESS}, null, new String[0], null, null, HombotDataContract.BotEntry.COLUMN_NAME_NAME);
mBotAdapter.changeCursor(botCursor);
}

@Override
public void onFinishEditDialog(String name, String address, long id) {
HombotDataOpenHelper dataHelper = new HombotDataOpenHelper(this);
SQLiteDatabase db = dataHelper.getWritableDatabase();

ContentValues values = new ContentValues();
values.put(HombotDataContract.BotEntry.COLUMN_NAME_NAME, name);
values.put(HombotDataContract.BotEntry.COLUMN_NAME_ADDRESS, address);
if (id > -1) {
db.update(HombotDataContract.BotEntry.TABLE_NAME, values, HombotDataContract.BotEntry._ID + "=" + id, null);
} else {
db.insertOrThrow(HombotDataContract.BotEntry.TABLE_NAME, null, values);
}

dataHelper.close();
loadBots();
}

}
Loading

0 comments on commit b9bb44f

Please sign in to comment.