Merge #456
This commit is contained in:
parent
26d67b4785
commit
a1aca9af41
5 changed files with 122 additions and 11 deletions
|
@ -49,9 +49,17 @@ android {
|
|||
exclude 'META-INF/LICENSE.txt'
|
||||
exclude 'META-INF/NOTICE.txt'
|
||||
exclude 'LICENSE.txt'
|
||||
exclude 'META-INF/services/javax.annotation.processing.Processor'
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
maven { url 'http://guardian.github.com/maven/repo-releases' } //needed for com.gu:option:1.3 in Android-DirectoryChooser
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// core android studio module
|
||||
//compile project(':core')
|
||||
|
@ -78,6 +86,7 @@ dependencies {
|
|||
compile 'org.apache.commons:commons-lang3:3.4'
|
||||
compile 'com.github.gabrielemariotti.changeloglib:changelog:2.0.0'
|
||||
compile 'org.jsoup:jsoup:1.7.2'
|
||||
compile ('net.rdrei.android.dirchooser:library:3.0@aar') { transitive = true; }
|
||||
|
||||
testCompile 'org.robolectric:robolectric:3.0-rc3'
|
||||
testCompile 'junit:junit:4.+'
|
||||
|
|
|
@ -18,14 +18,15 @@
|
|||
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
|
||||
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
|
||||
|
||||
<uses-sdk tools:overrideLibrary="android.support.customtabs" />
|
||||
<uses-sdk tools:overrideLibrary="android.support.customtabs"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme"
|
||||
android:name=".NewsReaderApplication">
|
||||
android:name=".NewsReaderApplication"
|
||||
tools:replace="android:icon, android:label, android:theme, android:name">
|
||||
<activity
|
||||
android:name=".NewsReaderListActivity"
|
||||
android:label="@string/app_name"
|
||||
|
@ -83,8 +84,11 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name="DirectoryChooserActivity" />
|
||||
|
||||
<receiver android:name=".events.podcast.broadcastreceiver.PodcastNotificationToggle" />
|
||||
|
||||
|
||||
<!--
|
||||
**********************************************************************
|
||||
* Sync Adapter and Service
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package de.luhmer.owncloudnewsreader;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.helper.ThemeChooser;
|
||||
|
||||
/**
|
||||
* Created by benson on 11/20/15.
|
||||
*/
|
||||
public class DirectoryChooserActivity extends net.rdrei.android.dirchooser.DirectoryChooserActivity {
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
int theme = ThemeChooser.isDarkTheme(getApplicationContext())
|
||||
? R.style.DirectoryChooserTheme
|
||||
: R.style.DirectoryChooserTheme_Light;
|
||||
setTheme(theme);
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ import android.content.ClipboardManager;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
@ -24,18 +25,19 @@ import android.widget.ListView;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.rdrei.android.dirchooser.DirectoryChooserConfig;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.helper.ThemeChooser;
|
||||
import uk.co.deanwild.materialshowcaseview.MaterialShowcaseView;
|
||||
|
||||
public class NewsDetailImageDialogFragment extends DialogFragment {
|
||||
|
||||
private static final int REQUEST_DIRECTORY = 0;
|
||||
public enum TYPE { IMAGE, URL }
|
||||
private static final String TAG = NewsDetailImageDialogFragment.class.getCanonicalName();
|
||||
|
||||
|
@ -80,7 +82,7 @@ public class NewsDetailImageDialogFragment extends DialogFragment {
|
|||
private DownloadManager downloadManager;
|
||||
private BroadcastReceiver downloadCompleteReceiver;
|
||||
|
||||
private HashMap<String, MenuAction> mMenuItems;
|
||||
private LinkedHashMap<String, MenuAction> mMenuItems;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -96,11 +98,12 @@ public class NewsDetailImageDialogFragment extends DialogFragment {
|
|||
//Build the menu
|
||||
switch(mDialogType) {
|
||||
case IMAGE:
|
||||
mMenuItems.put(getString(R.string.action_img_download), new MenuAction() {
|
||||
mMenuItems.put(getString(R.string.action_img_download), new MenuActionLongClick() {
|
||||
@Override
|
||||
public void execute() {
|
||||
downloadImage(mImageUrl);
|
||||
}
|
||||
public void executeLongClick() { changeDownloadDir(); }
|
||||
});
|
||||
mMenuItems.put(getString(R.string.action_img_open), new MenuAction() {
|
||||
@Override
|
||||
|
@ -150,8 +153,8 @@ public class NewsDetailImageDialogFragment extends DialogFragment {
|
|||
|
||||
int style = DialogFragment.STYLE_NO_TITLE;
|
||||
int theme = ThemeChooser.isDarkTheme(getActivity())
|
||||
? R.style.FloatingDialog
|
||||
: R.style.FloatingDialogLight;
|
||||
? R.style.Theme_Material_Dialog_Floating
|
||||
: R.style.Theme_Material_Light_Dialog_Floating;
|
||||
setStyle(style, theme);
|
||||
}
|
||||
|
||||
|
@ -210,6 +213,7 @@ public class NewsDetailImageDialogFragment extends DialogFragment {
|
|||
menuItemsList);
|
||||
|
||||
mListView.setAdapter(arrayAdapter);
|
||||
mListView.setLongClickable(true);
|
||||
|
||||
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
|
@ -219,6 +223,21 @@ public class NewsDetailImageDialogFragment extends DialogFragment {
|
|||
mAction.execute();
|
||||
}
|
||||
});
|
||||
|
||||
mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long id) {
|
||||
String key = arrayAdapter.getItem(position);
|
||||
try {
|
||||
MenuActionLongClick mAction = (MenuActionLongClick) mMenuItems.get(key);
|
||||
mAction.executeLongClick();
|
||||
} catch (ClassCastException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
@ -270,7 +289,7 @@ public class NewsDetailImageDialogFragment extends DialogFragment {
|
|||
String filename = url.getFile().substring(url.getFile().lastIndexOf('/') + 1, url.getFile().length());
|
||||
downloadManager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url.toString()));
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
|
||||
request.setDestinationUri(getDownloadDir(filename));
|
||||
request.setTitle("Downloading image");
|
||||
request.setDescription(filename);
|
||||
request.setVisibleInDownloadsUi(false);
|
||||
|
@ -283,6 +302,53 @@ public class NewsDetailImageDialogFragment extends DialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void changeDownloadDir() {
|
||||
final Intent chooserIntent = new Intent(getActivity(), DirectoryChooserActivity.class);
|
||||
final DirectoryChooserConfig config = DirectoryChooserConfig.builder()
|
||||
.initialDirectory(getActivity().getPreferences(Context.MODE_PRIVATE).getString("manualImageDownloadLocation", ""))
|
||||
.newDirectoryName("new folder")
|
||||
.allowNewDirectoryNameModification(true)
|
||||
.allowReadOnlyDirectory(false)
|
||||
.build();
|
||||
|
||||
chooserIntent.putExtra(DirectoryChooserActivity.EXTRA_CONFIG, config);
|
||||
startActivityForResult(chooserIntent, REQUEST_DIRECTORY);
|
||||
}
|
||||
|
||||
private void setNewDownloadDir(String path) {
|
||||
if(path.equals("")) {
|
||||
path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
|
||||
}
|
||||
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putString("manualImageDownloadLocation", path);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
private Uri getDownloadDir(String filename) {
|
||||
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
|
||||
String dir = sharedPref.getString("manualImageDownloadLocation", "");
|
||||
if(dir.equals("")) { //sharedPref has never been set
|
||||
setNewDownloadDir(""); //set to default public download dir
|
||||
return getDownloadDir(filename);
|
||||
}
|
||||
String tmp = "file://" +dir +"/" +filename;
|
||||
return Uri.parse(tmp);
|
||||
}
|
||||
|
||||
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == REQUEST_DIRECTORY) {
|
||||
if (resultCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) {
|
||||
String dir = data.getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR);
|
||||
setNewDownloadDir(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void unregisterImageDownloadReceiver() {
|
||||
if (downloadCompleteReceiver != null) {
|
||||
getActivity().unregisterReceiver(downloadCompleteReceiver);
|
||||
|
@ -333,4 +399,7 @@ public class NewsDetailImageDialogFragment extends DialogFragment {
|
|||
interface MenuAction {
|
||||
void execute();
|
||||
}
|
||||
interface MenuActionLongClick extends MenuAction {
|
||||
void executeLongClick();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,11 +56,18 @@
|
|||
</style>
|
||||
-->
|
||||
|
||||
<style name="FloatingDialog" parent="AppTheme" >
|
||||
<style name="DirectoryChooserTheme" parent="AppTheme" >
|
||||
<item name="android:background">@color/news_detail_background_color_dark_theme</item>
|
||||
</style>
|
||||
<style name="DirectoryChooserTheme_Light" parent="AppThemeLight" >
|
||||
<item name="android:background">@color/news_detail_background_color_light_theme</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Material.Dialog.Floating" parent="@android:style/Theme.Material.Dialog" >
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
<item name="android:windowCloseOnTouchOutside">true</item>
|
||||
</style>
|
||||
<style name="FloatingDialogLight" parent="AppThemeLight" >
|
||||
<style name="Theme.Material.Light.Dialog.Floating" parent="@android:style/Theme.Material.Light.Dialog" >
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
<item name="android:windowCloseOnTouchOutside">true</item>
|
||||
</style>
|
||||
|
|
Loading…
Reference in a new issue