diff options
author | David Development <david-dev@live.de> | 2016-04-17 17:32:16 +0300 |
---|---|---|
committer | David Development <david-dev@live.de> | 2016-04-17 17:32:16 +0300 |
commit | 3344c08137e3f82c33682bc87253a632120e9f55 (patch) | |
tree | 1141163d8f52c8386a95f2743febe34d77b58944 /News-Android-App/src/main/java | |
parent | ea02955cc0f0a274b881e4702161e0e84325690b (diff) | |
parent | bbbcdfdb4a00accd5cb9bf3ae5107aba4a5a46d4 (diff) |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'News-Android-App/src/main/java')
10 files changed, 86 insertions, 57 deletions
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java index 05c2b5ec..034ceefb 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java @@ -42,6 +42,7 @@ import android.os.RemoteException; import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.VisibleForTesting; import android.support.design.widget.Snackbar; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; @@ -845,11 +846,13 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements } } - protected NewsReaderListFragment getSlidingListFragment() { + @VisibleForTesting + public NewsReaderListFragment getSlidingListFragment() { return ((NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer)); } - protected NewsReaderDetailFragment getNewsReaderDetailFragment() { + @VisibleForTesting + public NewsReaderDetailFragment getNewsReaderDetailFragment() { return (NewsReaderDetailFragment) getSupportFragmentManager().findFragmentById(R.id.content_frame); } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListFragment.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListFragment.java index 16cc648c..a800cadb 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListFragment.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListFragment.java @@ -24,13 +24,13 @@ package de.luhmer.owncloudnewsreader; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; -import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; +import android.support.v7.widget.RecyclerView; import android.util.Base64; import android.util.Log; import android.util.TypedValue; @@ -65,6 +65,7 @@ import de.luhmer.owncloudnewsreader.helper.AsyncTaskHelper; import de.luhmer.owncloudnewsreader.helper.ThemeChooser; import de.luhmer.owncloudnewsreader.interfaces.ExpListTextClicked; import de.luhmer.owncloudnewsreader.model.FolderSubscribtionItem; +import de.luhmer.owncloudnewsreader.model.UserInfo; import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest; import de.luhmer.owncloudnewsreader.reader.owncloud.API; import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods; @@ -212,7 +213,7 @@ public class NewsReaderListFragment extends Fragment implements OnCreateContextM }; - OnChildClickListener onChildClickListener = new OnChildClickListener() { + public OnChildClickListener onChildClickListener = new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, @@ -248,7 +249,9 @@ public class NewsReaderListFragment extends Fragment implements OnCreateContextM - + public ExpandableListView getListView() { + return eListView; + } protected void showTapLogoToSyncShowcaseView() { @@ -279,7 +282,7 @@ public class NewsReaderListFragment extends Fragment implements OnCreateContextM return null; //API NOT SUPPORTED! - UserInfo ui = new UserInfo(); + UserInfo.Builder ui = new UserInfo.Builder(); InputStream inputStream = HttpJsonRequest.getInstance().PerformJsonRequest(api.getUserUrl()); JsonReader reader = new JsonReader(new InputStreamReader(inputStream, "UTF-8")); @@ -289,10 +292,10 @@ public class NewsReaderListFragment extends Fragment implements OnCreateContextM while(reader.hasNext() && (currentName = reader.nextName()) != null) { switch(currentName) { case "userId": - ui.mUserId = reader.nextString(); + ui.setUserId(reader.nextString()); break; case "displayName": - ui.mDisplayName = reader.nextString(); + ui.setDisplayName(reader.nextString()); break; case "avatar": com.google.gson.stream.JsonToken jt = reader.peek(); @@ -307,7 +310,7 @@ public class NewsReaderListFragment extends Fragment implements OnCreateContextM if (currentName.equals("data")) { String encodedImage = reader.nextString(); byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT); - ui.mAvatar = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); + ui.setAvatar(BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length)); Log.v(TAG, encodedImage); } else { reader.skipValue(); @@ -323,7 +326,7 @@ public class NewsReaderListFragment extends Fragment implements OnCreateContextM } reader.close(); - return ui; + return ui.build(); } catch (Exception e) { if(e.getMessage().equals("Method Not Allowed")) { //Remove if old version is used SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); @@ -351,6 +354,10 @@ public class NewsReaderListFragment extends Fragment implements OnCreateContextM } protected void bindUserInfoToUI() { + bindUserInfoToUI(false); + } + + public void bindUserInfoToUI(boolean testMode) { SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); String mUsername = mPrefs.getString(SettingsActivity.EDT_USERNAME_STRING, null); String mOc_root_path = mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, getString(R.string.app_name)); @@ -358,6 +365,10 @@ public class NewsReaderListFragment extends Fragment implements OnCreateContextM userTextView.setText(mUsername); urlTextView.setText(mOc_root_path); + if(testMode) { //Hide real url in test mode + urlTextView.setText("https://example.com/owncloud"); + } + String uInfo = mPrefs.getString("USER_INFO", null); if(uInfo == null) return; @@ -380,14 +391,8 @@ public class NewsReaderListFragment extends Fragment implements OnCreateContextM } - private class UserInfo implements Serializable { - private String mUserId; - private String mDisplayName; - private Bitmap mAvatar; - } - /** Read the object from Base64 string. */ - private static Object fromString(String s) throws IOException, + public static Object fromString(String s) throws IOException, ClassNotFoundException { byte [] data = Base64.decode(s, Base64.DEFAULT); ObjectInputStream ois = new ObjectInputStream( @@ -398,7 +403,7 @@ public class NewsReaderListFragment extends Fragment implements OnCreateContextM } /** Write the object to a Base64 string. */ - private static String toString(Serializable o) throws IOException { + public static String toString(Serializable o) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream( baos ); oos.writeObject(o); diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java index d888e057..e48c76b5 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java @@ -12,6 +12,7 @@ import android.content.res.Resources; import android.os.Build; import android.os.Bundle; import android.os.IBinder; +import android.support.annotation.VisibleForTesting; import android.support.v4.view.GravityCompat; import android.support.v7.app.AppCompatActivity; import android.util.Log; @@ -482,7 +483,8 @@ public class PodcastFragmentActivity extends AppCompatActivity implements IPlayP return px; } - protected void openMediaItem(MediaItem mediaItem) { + @VisibleForTesting + public void openMediaItem(MediaItem mediaItem) { Intent intent = new Intent(this, PodcastPlaybackService.class); if(mediaItem instanceof TTSItem) intent.putExtra(PodcastPlaybackService.TTS_ITEM, mediaItem); diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/GetImageThreaded.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/GetImageThreaded.java index 8e27922e..999bd7c8 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/GetImageThreaded.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/GetImageThreaded.java @@ -73,23 +73,23 @@ public class GetImageThreaded implements ImageLoadingListener @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { - NotifyDownloadFinished(); + NotifyDownloadFinished(null); Log.d(TAG, "Failed to load file: " + imageUri); } @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { - NotifyDownloadFinished(); + NotifyDownloadFinished(loadedImage); } @Override public void onLoadingCancelled(String imageUri, View view) { - NotifyDownloadFinished(); + NotifyDownloadFinished(null); Log.d(TAG, "Cancelled: " + imageUri); } - private void NotifyDownloadFinished() { + private void NotifyDownloadFinished(Bitmap bitmap) { if(imageDownloadFinished != null) - imageDownloadFinished.DownloadFinished(ThreadId); + imageDownloadFinished.DownloadFinished(ThreadId, bitmap); } } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java index ae0ca002..3dc9ac9f 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java @@ -46,10 +46,11 @@ public class DatabaseConnectionOrm { this.add("audio/ogg;codecs=opus"); this.add("audio/x-m4a"); this.add("youtube"); + this.add("video/mp4"); } }; - public static final String[] VIDEO_FORMATS = { "youtube" }; + public static final String[] VIDEO_FORMATS = { "youtube", "video/mp4" }; private final String TAG = getClass().getCanonicalName(); public enum SORT_DIRECTION { asc, desc } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/FavIconHandler.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/FavIconHandler.java index 5d69710b..efc47e0e 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/FavIconHandler.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/FavIconHandler.java @@ -73,19 +73,12 @@ public class FavIconHandler { return; } - GetImageThreaded giAsync = new GetImageThreaded(feed.getFaviconUrl(), favIconDownloadFinished, feed.getId()); - - giAsync.start(); + new GetImageThreaded(feed.getFaviconUrl(), favIconDownloadFinished, feed.getId()).start(); } ImageDownloadFinished favIconDownloadFinished = new ImageDownloadFinished() { @Override - public void DownloadFinished(long AsynkTaskId) { - DownloadFinished(AsynkTaskId, null); - } - - @Override public void DownloadFinished(long AsynkTaskId, Bitmap bitmap) { if(bitmap != null) { DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context); diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/ImageDownloadFinished.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/ImageDownloadFinished.java index ec8a3b11..f570f34b 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/ImageDownloadFinished.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/ImageDownloadFinished.java @@ -25,6 +25,5 @@ package de.luhmer.owncloudnewsreader.helper; import android.graphics.Bitmap; public interface ImageDownloadFinished { - void DownloadFinished(long AsynkTaskId); void DownloadFinished(long AsynkTaskId, Bitmap bitmap); } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/model/UserInfo.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/model/UserInfo.java new file mode 100644 index 00000000..3fd2ce8a --- /dev/null +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/model/UserInfo.java @@ -0,0 +1,46 @@ +package de.luhmer.owncloudnewsreader.model; + +import android.graphics.Bitmap; + +import java.io.Serializable; + +/** + * Created by dluhmer on 19.03.16. + */ +public class UserInfo implements Serializable { + + public static class Builder { + private String userId; + private String displayName; + private Bitmap avatar; + + public Builder setUserId(String userId) { + this.userId = userId; + return this; + } + + public Builder setDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + public Builder setAvatar(Bitmap avatar) { + this.avatar = avatar; + return this; + } + + public UserInfo build() { + return new UserInfo(userId, displayName, avatar); + } + } + + private UserInfo(String userId, String displayName, Bitmap avatar) { + this.mUserId = userId; + this.mDisplayName = displayName; + this.mAvatar = avatar; + } + + public final String mUserId; + public final String mDisplayName; + public final Bitmap mAvatar; +} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/InsertIntoDatabase.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/InsertIntoDatabase.java index baa3464d..793534d6 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/InsertIntoDatabase.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/InsertIntoDatabase.java @@ -89,21 +89,6 @@ public class InsertIntoDatabase { break; } - /* - if(feeds.get(i).getLink().equals(oldFeed.getLink())) - { - if(!feeds.get(i).getFeedTitle().equals(oldFeed.getFeedTitle())) - { - oldFeed.setFeedTitle(feeds.get(i).getFeedTitle()); - } - //Set the avg color after sync again. - oldFeed.setAvgColour(oldFeeds.get(i).getAvgColour()); - dbConn.updateFeed(oldFeed); - - found = true; - break; - } - */ } if(!found) { diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/DownloadImagesService.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/DownloadImagesService.java index 6ad74501..6f3186ea 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/DownloadImagesService.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/DownloadImagesService.java @@ -191,12 +191,12 @@ public class DownloadImagesService extends IntentService { ImageDownloadFinished imgDownloadFinished = new ImageDownloadFinished() { - @Override - public void DownloadFinished(long ThreadId) { + @Override + public void DownloadFinished(long AsynkTaskId, Bitmap bitmap) { int count = maxCount - linksToImages.size(); if(maxCount == count) { - notificationManager.cancel(NOTIFICATION_ID); + notificationManager.cancel(NOTIFICATION_ID); //RemoveOldImages(); } else { mNotificationDownloadImages @@ -207,11 +207,6 @@ public class DownloadImagesService extends IntentService { StartNextDownloadInQueue(); } - } - - @Override - public void DownloadFinished(long AsynkTaskId, Bitmap bitmap) { - DownloadFinished(AsynkTaskId); } }; } |