code cleanup/refactoring

This commit is contained in:
David Development 2015-01-17 15:12:22 +01:00
parent 205d0c1b94
commit 8ebd7b10c9
8 changed files with 121 additions and 203 deletions

View file

@ -32,6 +32,7 @@ import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.ListFragment;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

View file

@ -27,6 +27,7 @@ import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Build;
import android.os.Bundle;
import android.os.RemoteException;
@ -38,6 +39,7 @@ import android.support.v4.widget.SlidingPaneLayout;
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -46,6 +48,8 @@ import com.github.amlcurran.showcaseview.OnShowcaseEventListener;
import com.github.amlcurran.showcaseview.ShowcaseView;
import com.github.amlcurran.showcaseview.targets.ViewTarget;
import java.util.List;
import butterknife.ButterKnife;
import butterknife.InjectView;
import de.greenrobot.event.EventBus;
@ -53,7 +57,12 @@ import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter;
import de.luhmer.owncloudnewsreader.LoginDialogFragment.LoginSuccessfullListener;
import de.luhmer.owncloudnewsreader.adapter.NewsListArrayAdapter;
import de.luhmer.owncloudnewsreader.authentication.AccountGeneral;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.database.DatabaseHelperOrm;
import de.luhmer.owncloudnewsreader.database.model.DaoSession;
import de.luhmer.owncloudnewsreader.database.model.Feed;
import de.luhmer.owncloudnewsreader.database.model.Folder;
import de.luhmer.owncloudnewsreader.events.podcast.FeedPanelSlideEvent;
import de.luhmer.owncloudnewsreader.helper.DatabaseUtils;
import de.luhmer.owncloudnewsreader.helper.ImageHandler;
@ -189,7 +198,77 @@ public class NewsReaderListActivity extends MenuUtilsFragmentActivity implements
ImageHandler.createNoMediaFile(this);
//AppRater.app_launched(this);
//AppRater.rateNow(this);
/*
new Thread(new Runnable() {
@Override
public void run() {
startTesting();
}
}).start();
*/
}
/* TEST!!! */
public void startTesting() {
try {
Thread.sleep(10000); //Wait 10 Seconds
} catch (InterruptedException e) {
e.printStackTrace();
}
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(activity);
DaoSession daoSession = DatabaseHelperOrm.getDaoSession(activity);
List<Feed> feedList = dbConn.getAllFeedsWithUnreadRssItems();
List<Folder> folderList = dbConn.getListOfFolders();
long avgTime = 0;
final int runs = 100;
for(int i = 0; i < runs; i++) {
long start = System.currentTimeMillis();
/* Test 1 */
/*
for (Feed feed : feedList) {
String query = dbConn.getAllItemsIdsForFeedSQL(feed.getId(), true, false, DatabaseConnection.SORT_DIRECTION.asc);
Cursor c = daoSession.getDatabase().rawQuery(query, null);
if(c != null) {
c.moveToFirst();
do {
int xcv = c.getInt(0);
} while (c.moveToNext());
}
}
*/
/* Test 1 Ende */
/* Test 2 */
for (Folder folder : folderList) {
String query = dbConn.getAllItemsIdsForFolderSQL(folder.getId(), true, DatabaseConnection.SORT_DIRECTION.asc);
dbConn.insertIntoRssCurrentViewTable(query);
//Log.d(TAG, "Inserting time needed: " + (System.currentTimeMillis() - start) + " ms");
}
/* Test 2 Ende */
avgTime += (System.currentTimeMillis() - start);
}
avgTime /= runs;
Log.d(TAG, "Time needed in average:" + avgTime + " ms");
}
/* TEST ENDE!!! */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)

View file

@ -40,6 +40,9 @@ public class InsertIntoDatabase {
public static void InsertFoldersIntoDatabase(List<Folder> folderList, DatabaseConnectionOrm dbConn)
{
dbConn.deleteOldAndInsertNewFolders(folderList.toArray(new Folder[folderList.size()]));
/*
List<Feed> feeds = dbConn.getListOfFeeds();
List<String> tagsAvailable = new ArrayList<String>(feeds.size());
@ -47,9 +50,6 @@ public class InsertIntoDatabase {
tagsAvailable.add(feeds.get(i).getFeedTitle());
//dbConn.getDatabase().beginTransaction();
try
{
if(folderList != null)
{
int addedCount = 0;
@ -64,42 +64,16 @@ public class InsertIntoDatabase {
}
}
//List<String> newLabelList = new ArrayList<String>();
/*
for(String[] subTag : tags)
newLabelList.add(subTag[0]);
*/
/*
for(String tag : tagsAvailable)
{
if(!newLabelList.contains(tag))
{
int result = dbConn.removeFolderByFolderLabel(tag);//TODO this line is needed!!!!
Log.d(TAG, "Result delete: " + result);
}
}
*/
Log.d("ADD", ""+ addedCount);
Log.d("REMOVE", ""+ removedCount++);
}
//dbConn.getDatabase().setTransactionSuccessful();
} finally {
//dbConn.getDatabase().endTransaction();
}
//dbConn.closeDatabase();
*/
}
public static void InsertFeedsIntoDatabase(ArrayList<Feed> newFeeds, DatabaseConnectionOrm dbConn)
{
List<Feed> oldFeeds = dbConn.getListOfFeeds();
try
{
if(newFeeds != null)
{
for(Feed feed : newFeeds)
@ -127,51 +101,5 @@ public class InsertIntoDatabase {
}
}
}
//dbConn.getDatabase().setTransactionSuccessful();
} finally {
//dbConn.getDatabase().endTransaction();
}
//dbConn.closeDatabase();
}
public static void InsertRssItemsIntoDatabase(List<RssItem> files, Activity activity)
{
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(activity);
if(files != null) {
dbConn.insertNewItems(files.toArray(new RssItem[files.size()]));
}
/*
dbConn.getDatabase().beginTransaction();
try
{
if(files != null)
{
for (RssItem rssFile : files)
InsertSingleFeedItemIntoDatabase(rssFile, dbConn);
}
dbConn.getDatabase().setTransactionSuccessful();
} finally {
dbConn.getDatabase().endTransaction();
}
dbConn.closeDatabase();
*/
}
public static boolean InsertSingleFeedItemIntoDatabase(RssItem rssFile, DatabaseConnectionOrm dbConn)
{
boolean newItem = false;
if(rssFile != null)
{
//Boolean isFeedAlreadyInDatabase = dbConn.doesRssItemAlreadyExsists(rssFile.getId());
dbConn.insertNewItems(rssFile);
newItem = !rssFile.getRead();
}
return newItem;
}
}

View file

@ -122,8 +122,6 @@ public class AsyncTask_GetItems extends AsyncTask_Reader {
} catch (Exception ex) {
ex.printStackTrace();
return ex;
} finally {
//dbConn.closeDatabase();
}
return null;
}

View file

@ -129,12 +129,10 @@ public class InsertItemIntoDatabase implements IHandleJsonObject {
public boolean performDatabaseBatchInsert() {
if(index > 0) {
//dbConn.insertNewItems(buffer);
dbConn.insertNewItems(buffer.toArray(new RssItem[buffer.size()]));
index = 0;
//buffer = new RssItem[bufferSize];
buffer = new ArrayList<RssItem>(bufferSize);
buffer = new ArrayList<>(bufferSize);
}
return true;

View file

@ -81,7 +81,6 @@ public class OwnCloudReaderMethods {
else if(api instanceof APIv2)
return readJsonStreamV2(is, new InsertItemIntoDatabase(dbConn));
} finally {
//dbConn.closeDatabase();//TODO this line is needed
is.close();
}
return new int[] { 0, 0 };
@ -119,7 +118,6 @@ public class OwnCloudReaderMethods {
else if(api instanceof APIv2)
return readJsonStreamV2(is, new InsertItemIntoDatabase(dbConn))[0];
} finally {
//dbConn.closeDatabase();//TODO this line is needed
is.close();
}
return 0;
@ -142,7 +140,6 @@ public class OwnCloudReaderMethods {
ifid.WriteAllToDatabaseNow();
} finally {
//dbConn.closeDatabase();//TODO this line is needed
is.close();
}
@ -165,7 +162,6 @@ public class OwnCloudReaderMethods {
ifid.WriteAllToDatabaseNow();
} finally {
//dbConn.closeDatabase();//TODO this line is needed
inputStream.close();
}
return result;

View file

@ -1,62 +0,0 @@
package de.luhmer.owncloudnewsreader.reader.owncloud.apiv2;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import java.util.List;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.database.model.Feed;
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudConstants;
/**
* Created by david on 13.01.14.
*/
public class AsyncTask_TriggerOcUpdate extends AsyncTask_Reader {
private String username;
private String password;
public AsyncTask_TriggerOcUpdate(final int task_id, final Context context, String username, String password, final OnAsyncTaskCompletedListener[] listener) {
super(task_id, context, listener);
this.username = username;
this.password = password;
}
@Override
protected Object doInBackground(Object... params) {
try {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
String oc_path = mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, "") + OwnCloudConstants.ROOT_PATH_APIv2 + "feeds/update" + OwnCloudConstants.JSON_FORMAT;
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context);
List<Feed> feedList = dbConn.getListOfFeeds();
/*
if(cursor.getCount() > 0) {
cursor.moveToFirst();
do {
String feedId = cursor.getString(cursor.getColumnIndex(DatabaseConnection.SUBSCRIPTION_ID));
List<NameValuePair> nValuePairs = new ArrayList<NameValuePair>();
nValuePairs.add(new BasicNameValuePair("userId", username));
nValuePairs.add(new BasicNameValuePair("feedId", feedId));
HttpJsonRequest.PerformJsonRequest(oc_path, nValuePairs, username, password, context);
} while(cursor.moveToNext());
}
*/
return true;
} catch (Exception ex) {
return ex;
}
}
}

View file

@ -47,8 +47,6 @@ import de.luhmer.owncloudnewsreader.reader.IReader;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloud_Reader;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.AsyncTask_TriggerOcUpdate;
import de.luhmer.owncloudnewsreader.services.IOwnCloudSyncService.Stub;
import de.luhmer.owncloudnewsreader.widget.WidgetProvider;
@ -210,18 +208,6 @@ public class OwnCloudSyncService extends Service {
}
UpdateWidget();
}
if(_Reader instanceof OwnCloud_Reader) {
API api = ((OwnCloud_Reader)_Reader).getApi();
if(api instanceof APIv2) {
new AsyncTask_TriggerOcUpdate(0,
OwnCloudSyncService.this,
api.getUsername(),
api.getPassword(),
new OnAsyncTaskCompletedListener[] { onAsyncTask_UpdateOcFeeds })
.execute((Void) null);
}
}
}
Log.d(TAG, "onAsyncTask_GetItems Finished");
@ -230,12 +216,6 @@ public class OwnCloudSyncService extends Service {
}
};
OnAsyncTaskCompletedListener onAsyncTask_UpdateOcFeeds = new OnAsyncTaskCompletedListener() {
@Override
public void onAsyncTaskCompleted(int task_id, Object task_result) {
}
};
private void UpdateWidget()
{