code cleanup of previous commits

This commit is contained in:
benjamin stephan 2015-12-15 18:11:26 +01:00
parent 850ec0374f
commit c5230228aa
8 changed files with 115 additions and 154 deletions

View file

@ -139,13 +139,11 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
//private Date mLastSyncDate = new Date(0);
private boolean mSyncOnStartupPerformed = false;
@InjectView(R.id.toolbar)
Toolbar toolbar;
@InjectView(R.id.toolbar) Toolbar toolbar;
private ServiceConnection mConnection = null;
@Optional
@InjectView(R.id.drawer_layout)
@Optional @InjectView(R.id.drawer_layout)
protected DrawerLayout drawerLayout;
private ActionBarDrawerToggle drawerToggle;
@ -373,9 +371,6 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
drawerToggle.onConfigurationChanged(newConfig);
}
public void switchToAllUnreadItems() {
StartDetailFragment(SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_UNREAD_ITEMS.getValue(), true, null, true);
}
public void reloadCountNumbersOfSlidingPaneAdapter() {
NewsReaderListFragment nlf = getSlidingListFragment();
if (nlf != null) {
@ -383,7 +378,7 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
}
}
public void updateCurrentRssView() {
protected void updateCurrentRssView() {
NewsReaderDetailFragment ndf = getNewsReaderDetailFragment();
if (ndf != null) {
//ndf.reloadAdapterFromScratch();
@ -391,6 +386,10 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
}
}
public void switchToAllUnreadItemsFolder() {
StartDetailFragment(SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_UNREAD_ITEMS.getValue(), true, null, true);
}
@Override
protected void onStart() {
Intent serviceIntent = new Intent(this, OwnCloudSyncService.class);
@ -580,7 +579,6 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
if (drawerLayout != null)
drawerLayout.closeDrawer(GravityCompat.START);
//StartDetailFragment(idSubscription, false, optional_folder_id);
StartDetailFragment(idFeed, false, optional_folder_id, true);
}
@ -596,29 +594,25 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
private void StartDialogFragment(long idFeed, Boolean isFolder, Long optional_folder_id) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment prev = getSupportFragmentManager().findFragmentByTag("news_reader_list_dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(getApplicationContext());
if (isFolder) {
//top-folder long-clicked
if(idFeed >= 0) {
String titel = dbConn.getFolderById(idFeed).getLabel();
System.out.println("*************************folderlongclicked: " +titel);
//currently no actions for folders
//String titel = dbConn.getFolderById(idFeed).getLabel();
}
} else {
//top-item long-clicked
String titel = dbConn.getFeedById(idFeed).getFeedTitle();
String iconurl = dbConn.getFeedById(idFeed).getFaviconUrl();
String feedurl = dbConn.getFeedById(idFeed).getLink();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment prev = getSupportFragmentManager().findFragmentByTag("news_reader_list_dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
NewsReaderListDialogFragment fragment = NewsReaderListDialogFragment.newInstance(idFeed, titel, iconurl, feedurl);
fragment.setActivity(this);
fragment.show(ft, "news_reader_list_dialog");
@ -674,7 +668,7 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
}
void startSync()
public void startSync()
{
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
@ -889,11 +883,11 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
}
}
public /*private*/ NewsReaderListFragment getSlidingListFragment() {
protected NewsReaderListFragment getSlidingListFragment() {
return ((NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer));
}
public NewsReaderDetailFragment getNewsReaderDetailFragment() {
protected NewsReaderDetailFragment getNewsReaderDetailFragment() {
return (NewsReaderDetailFragment) getSupportFragmentManager().findFragmentById(R.id.content_frame);
}
@ -913,7 +907,7 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
}
public /*private*/ void UpdateListView()
private void UpdateListView()
{
getNewsReaderDetailFragment().notifyDataSetChangedOnAdapter();
}

View file

@ -35,9 +35,6 @@ import de.luhmer.owncloudnewsreader.reader.owncloud.API;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;
/**
* Created by benson on 27/11/15.
*/
public class NewsReaderListDialogFragment extends DialogFragment{
static NewsReaderListDialogFragment newInstance(long feedId, String dialogTitle, String iconurl, String feedurl) {
@ -59,7 +56,6 @@ public class NewsReaderListDialogFragment extends DialogFragment{
private String mDialogText;
private String mDialogIconUrl;
private FavIconHandler favIconHandler;
private RemoveFeedTask mRemoveFeedTask = null;
private RenameFeedTask mRenameFeedTask = null;
private LinkedHashMap<String, MenuAction> mMenuItems;
@ -85,14 +81,14 @@ public class NewsReaderListDialogFragment extends DialogFragment{
mMenuItems.put(getString(R.string.action_feed_rename), new MenuAction() {
@Override
public void execute() {
attemptRenameFeed(mFeedId, mDialogTitle);
showRenameFeedView(mFeedId, mDialogTitle);
}
});
mMenuItems.put(getString(R.string.action_feed_remove), new MenuAction() {
@Override
public void execute() {
attemptRemoveFeed(mFeedId);
showRemoveFeedView(mFeedId);
}
});
@ -110,8 +106,8 @@ public class NewsReaderListDialogFragment extends DialogFragment{
View v = inflater.inflate(R.layout.fragment_dialog_feedoptions, container, false);
TextView tvTitle = (TextView) v.findViewById(R.id.ic_menu_title);
TextView tvText = (TextView) v.findViewById(R.id.ic_menu_item_text);
TextView tvTitle = (TextView) v.findViewById(R.id.tv_menu_title);
TextView tvText = (TextView) v.findViewById(R.id.tv_menu_text);
ImageView imgTitle = (ImageView) v.findViewById(R.id.ic_menu_feedicon);
mRemoveFeedDialogView = (RelativeLayout) v.findViewById(R.id.remove_feed_dialog);
@ -123,13 +119,16 @@ public class NewsReaderListDialogFragment extends DialogFragment{
mButtonRenameCancel = (Button) v.findViewById(R.id.button_rename_cancel);
mFeedName = (EditText) v.findViewById(R.id.renamefeed_feedname);
FavIconHandler favIconHandler = new FavIconHandler(getContext());
favIconHandler.loadFavIconForFeed(mDialogIconUrl, imgTitle);
tvTitle.setText(mDialogTitle);
tvText.setText(mDialogText);
tvText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mDialogText != null) {
if (mDialogText != null) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(mDialogText));
startActivity(i);
@ -137,10 +136,7 @@ public class NewsReaderListDialogFragment extends DialogFragment{
}
});
favIconHandler = new FavIconHandler(getContext());
favIconHandler.loadFavIconForFeed(mDialogIconUrl, imgTitle);
mListView = (ListView) v.findViewById(R.id.xx_menu_item_list);
mListView = (ListView) v.findViewById(R.id.lv_menu_list);
List<String> menuItemsList = new ArrayList<>(mMenuItems.keySet());
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(
@ -158,8 +154,6 @@ public class NewsReaderListDialogFragment extends DialogFragment{
mAction.execute();
}
});
return v;
}
@ -183,8 +177,7 @@ public class NewsReaderListDialogFragment extends DialogFragment{
}
private void attemptRenameFeed(final long feedId, final String feedName) {
private void showRenameFeedView(final long feedId, final String feedName) {
mFeedName.setText(feedName);
mButtonRenameConfirm.setEnabled(false);
@ -192,7 +185,6 @@ public class NewsReaderListDialogFragment extends DialogFragment{
mRenameFeedDialogView.setVisibility(View.VISIBLE);
mFeedName.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {}
@ -211,7 +203,6 @@ public class NewsReaderListDialogFragment extends DialogFragment{
}
});
mButtonRenameCancel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dismiss();
@ -223,14 +214,14 @@ public class NewsReaderListDialogFragment extends DialogFragment{
showProgress(true);
setCancelable(false);
getDialog().setCanceledOnTouchOutside(false);
mRenameFeedTask = new RenameFeedTask(feedId, mFeedName.getText().toString() ); //TODO needs testing!
mRenameFeedTask = new RenameFeedTask(feedId, mFeedName.getText().toString() );
mRenameFeedTask.execute((Void) null);
}
});
}
private void attemptRemoveFeed(final long feedId) {
private void showRemoveFeedView(final long feedId) {
mListView.setVisibility(View.GONE);
mRemoveFeedDialogView.setVisibility(View.VISIBLE);
@ -245,19 +236,13 @@ public class NewsReaderListDialogFragment extends DialogFragment{
showProgress(true);
setCancelable(false);
getDialog().setCanceledOnTouchOutside(false);
mRemoveFeedTask = new RemoveFeedTask(feedId); //TODO needs testing!
mRemoveFeedTask = new RemoveFeedTask(feedId);
mRemoveFeedTask.execute((Void) null);
}
});
}
interface MenuAction {
void execute();
}
public class RemoveFeedTask extends AsyncTask<Void, Void, Boolean> {
private final long mFeedId;
@ -294,15 +279,10 @@ public class NewsReaderListDialogFragment extends DialogFragment{
Long currentFeedId = parentActivity.getNewsReaderDetailFragment().getIdFeed();
if(currentFeedId != null && currentFeedId == mFeedId) {
parentActivity.switchToAllUnreadItems();
parentActivity.switchToAllUnreadItemsFolder();
}
parentActivity.getSlidingListFragment().ReloadAdapter();
parentActivity.updateCurrentRssView();
//parentActivity.UpdateItemList();
//parentActivity.UpdateListView();
//parentActivity.getSlidingListFragment().ListViewNotifyDataSetChanged();
//parentActivity.startSync();
} else {
Toast.makeText(getContext().getApplicationContext(), getString(R.string.login_dialog_text_something_went_wrong), Toast.LENGTH_LONG).show();
}
@ -353,7 +333,6 @@ public class NewsReaderListDialogFragment extends DialogFragment{
dbConn.renameFeedById(mFeedId, mFeedName);
parentActivity.getSlidingListFragment().ReloadAdapter();
//parentActivity.updateCurrentRssView();
parentActivity.startSync();
} else {
Toast.makeText(getContext().getApplicationContext(), getString(R.string.login_dialog_text_something_went_wrong), Toast.LENGTH_LONG).show();
@ -367,4 +346,9 @@ public class NewsReaderListDialogFragment extends DialogFragment{
dismiss();
}
}
interface MenuAction {
void execute();
}
}

View file

@ -41,10 +41,8 @@ import butterknife.ButterKnife;
import butterknife.InjectView;
import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.database.model.Feed;
import de.luhmer.owncloudnewsreader.helper.ThemeChooser;
import de.luhmer.owncloudnewsreader.interfaces.ExpListTextClicked;
import de.luhmer.owncloudnewsreader.model.ConcreteFeedItem;
import de.luhmer.owncloudnewsreader.model.FolderSubscribtionItem;
/**

View file

@ -327,27 +327,18 @@ public class DatabaseConnectionOrm {
return feeds.size() > 0;
}
public void removeFeedById(long feedId) {
daoSession.getFeedDao().deleteByKey(feedId);
List<RssItem> list = daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.FeedId.eq(feedId)).list();
for (RssItem rssItem : list) {
//if(!rssItem.getStarred() && !rssItem.getStarred_temp()) {
daoSession.getRssItemDao().delete(rssItem);
//}
daoSession.getRssItemDao().delete(rssItem);
}
}
public void renameFeedById(long feedId, String newTitle) {
Feed feed = daoSession.getFeedDao().queryBuilder().where(FeedDao.Properties.Id.eq(feedId)).unique();
feed.setFeedTitle(newTitle);
/*
List<RssItem> list = daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.FeedId.eq(feedId)).list();
for (RssItem rssItem : list) {
rssItem.setFeed(feed);
}
*/
daoSession.getFeedDao().update(feed);
}

View file

@ -189,7 +189,6 @@ public class HttpJsonRequest {
return response.code();
}
public int performRemoveFeedRequest(HttpUrl url, long feedId) throws Exception {
HttpUrl feedUrl = url.newBuilder()
.addPathSegment(String.valueOf(feedId))
@ -205,7 +204,6 @@ public class HttpJsonRequest {
return response.code();
}
public int performRenameFeedRequest(HttpUrl url, long feedId, String newFeedName) throws Exception {
HttpUrl feedUrl = url.newBuilder()
.addPathSegment(String.valueOf(feedId))
@ -222,8 +220,6 @@ public class HttpJsonRequest {
return response.code();
}
public int performTagChangeRequest(HttpUrl url, String content) throws Exception
{
Request request = new Request.Builder()

View file

@ -50,8 +50,8 @@ public class InsertFeedIntoDatabase implements IHandleJsonObject{
feed.setFeedTitle(e.optString("title"));
feed.setFolderId(e.optLong("folderId"));
feed.setFaviconUrl(faviconLink);
//feed.setLink(e.optString("link"));
feed.setLink(e.optString("url"));
//feed.setLink(e.optString("link"));
return feed;
}

View file

@ -1,121 +1,119 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:paddingBottom="6dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin">
android:paddingTop="@dimen/activity_vertical_margin">
<RelativeLayout
android:id="@+id/title_wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:layout_marginBottom="4dp"
android:id="@+id/title_wrapper">
android:padding="6dp">
<ImageView
android:id="@+id/ic_menu_feedicon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:id="@+id/ic_menu_feedicon"/>
android:layout_gravity="center_vertical"/>
<TextView
android:id="@+id/tv_menu_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:id="@+id/ic_menu_title"
tools:text="Sample1"
android:layout_centerVertical="true"
android:layout_marginStart="5dp"
android:layout_toEndOf="@+id/ic_menu_feedicon"
android:layout_toRightOf="@+id/ic_menu_feedicon"
android:textSize="16sp"
android:textStyle="bold"
android:layout_toRightOf="@+id/ic_menu_feedicon"
android:layout_toEndOf="@+id/ic_menu_feedicon"/>
tools:text="NameOfFeed"/>
</RelativeLayout>
<TextView
android:id="@+id/tv_menu_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="6dp"
android:id="@+id/ic_menu_item_text"
tools:text="Sample1"
android:textSize="14sp"
android:layout_marginTop="2dp"
android:layout_below="@+id/title_wrapper"
android:textStyle="normal"/>
android:layout_marginTop="2dp"
android:paddingEnd="6dp"
android:paddingStart="6dp"
android:textSize="14sp"
android:textStyle="normal"
tools:text="UrlOfFeed"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="12dp"
android:layout_below="@+id/tv_menu_text"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:background="#c8ababab"
android:layout_below="@+id/ic_menu_item_text"/>
android:layout_marginTop="12dp"
android:background="#c8ababab"/>
<ListView
android:id="@+id/lv_menu_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_menu_text"
android:layout_marginTop="13dp"
android:divider="@null"
android:id="@+id/xx_menu_item_list"
android:layout_below="@+id/ic_menu_item_text">
</ListView>
android:divider="@null"/>
<RelativeLayout
android:id="@+id/remove_feed_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ic_menu_item_text"
android:layout_below="@+id/tv_menu_text"
android:layout_marginTop="13dp"
android:visibility="gone">
<TextView
android:layout_marginTop="13dp"
android:id="@+id/tv_detail_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingRight="6dp"
android:paddingLeft="6dp"
android:textSize="18sp"
android:id="@+id/textView"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="true"
android:text="Do you really want to remove this Feed?
This cannot be undone!"
android:layout_marginBottom="13dp"></TextView>
android:layout_marginBottom="13dp"
android:layout_marginTop="13dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:text="@string/confirm_feed_remove"
android:textSize="18sp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/tv_detail_text"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp">
android:layout_marginRight="0dp"
android:orientation="horizontal">
<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_height="wrap_content"
android:text="Cancel"
android:id="@+id/button_remove_cancel"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_marginLeft="0dp" />
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_weight="1"
android:text="@android:string/cancel" />
<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_height="wrap_content"
android:text="Remove"
android:id="@+id/button_remove_confirm"
android:layout_toEndOf="@id/button_remove_confirm"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_marginRight="0dp" />
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_weight="1"
android:text="@string/feed_remove_button" />
</LinearLayout>
</RelativeLayout>
@ -124,54 +122,52 @@
android:id="@+id/rename_feed_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ic_menu_item_text"
android:layout_below="@+id/tv_menu_text"
android:layout_marginTop="13dp"
android:visibility="gone">
<EditText
android:layout_marginTop="13dp"
android:paddingRight="6dp"
android:paddingLeft="6dp"
android:id="@+id/renamefeed_feedname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/renamefeed_feedname"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="true"
android:textSize="18sp"
android:text="Do you really want to remove this Feed? This cannot be undone!"
android:layout_marginBottom="13dp"
android:singleLine="true"
android:lines="1"
android:layout_marginTop="13dp"
android:imeOptions="actionDone"
android:inputType="textVisiblePassword"></EditText>
android:inputType="textVisiblePassword"
android:lines="1"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:singleLine="true"
android:textSize="18sp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/renamefeed_feedname"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/renamefeed_feedname"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp">
android:layout_marginRight="0dp"
android:orientation="horizontal">
<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_height="wrap_content"
android:text="Cancel"
android:id="@+id/button_rename_cancel"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_marginLeft="0dp" />
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_weight="1"
android:text="@android:string/cancel" />
<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_height="wrap_content"
android:text="Rename"
android:id="@+id/button_rename_confirm"
android:layout_toEndOf="@id/button_rename_cancel"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_marginRight="0dp" />
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_weight="1"
android:text="@string/feed_rename_button" />
</LinearLayout>
</RelativeLayout>
@ -180,7 +176,7 @@
android:id="@+id/progressView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ic_menu_item_text"
android:layout_below="@+id/tv_menu_text"
android:layout_marginTop="13dp"
android:visibility="gone">
<ProgressBar

View file

@ -73,8 +73,10 @@
<!-- Strings related to NewsReaderListDialogFragment (Rename/Remove Feed) -->
<string name="action_feed_remove">Remove Feed</string>
<string name="action_feed_rename">Rename Feed</string>
<string name="feed_remove_button">Remove</string>
<string name="feed_rename_button">Rename</string>
<string name="confirm_feed_remove">Do you really want to remove this Feed? This cannot be undone!</string>
<!-- Strings related to login -->
<string name="pref_title_username">Username</string>
<string name="pref_title_password">Password</string>