Skip to content

Commit

Permalink
Merge branch 'central-dev' into central-master
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbWatershed committed Jul 25, 2019
2 parents e0079d0 + 5e825c4 commit 72ccbac
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 42 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
//noinspection ExpiringTargetSdkVersion
targetSdkVersion 28
versionCode 110 // is updated automatically by BitRise; only used when building locally
versionName '1.8.4'
versionName '1.8.5'

def fkToken = '\"' + (System.getenv("FK_TOKEN")?: "")+'\"'
def includeObjectBoxBrowser = System.getenv("INCLUDE_OBJECTBOX_BROWSER")?:"false"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<uses-permission android:name="android.permission.VIBRATE" />
<!-- Required to run keep-alive service when targeting API 28 or higher -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<!-- Required to install update packages when targeting API 25 or higher -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>

<application
android:name=".HentoidApp"
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/me/devsaki/hentoid/HentoidApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,23 @@ public void onCreate() {
// DB housekeeping
performDatabaseHousekeeping();

// Init notifications
// Init notification channels
UpdateNotificationChannel.init(this);
DownloadNotificationChannel.init(this);
MaintenanceNotificationChannel.init(this);

// Clears all previous notifications
NotificationManager manager = (NotificationManager) instance.getSystemService(Context.NOTIFICATION_SERVICE);
if (manager != null) manager.cancelAll();

// Run app update checks
Intent intent = UpdateCheckService.makeIntent(this, false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent);
} else {
startService(intent);
}

// Clears all previous notifications
NotificationManager manager = (NotificationManager) instance.getSystemService(Context.NOTIFICATION_SERVICE);
if (manager != null) manager.cancelAll();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutHelper.buildShortcuts(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,7 @@ public void onDownloadEvent(DownloadEvent event) {
}

private void openBook(Content content) {
// The list order might change when viewing books when certain sort orders are activated
// "unread" status might also change
// => plan a refresh next time DownloadsFragment is called
plannedRefresh = true;
// TODO : plan an individual refresh of displayed books according to their new DB value (esp. read/unread)
Bundle bundle = new Bundle();
searchManager.saveToBundle(bundle);
int pageOffset = 0;
Expand Down Expand Up @@ -560,6 +557,7 @@ protected void attachOnClickListeners(View rootView) {

filterClearButton.setOnClickListener(v -> {
setQuery("");
mainSearchView.setQuery("", false);
searchManager.clearSelectedSearchTags();
filterBar.setVisibility(View.GONE);
searchLibrary();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public void onDownloadEvent(DownloadEvent event) {
break;
case DownloadEvent.EV_COMPLETE:
mAdapter.removeFromQueue(event.content);
dlPreparationProgressBar.setVisibility(View.GONE);
if (0 == mAdapter.getCount()) btnStats.setVisibility(View.GONE);
update(event.eventType);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityOptionsCompat;
import androidx.fragment.app.Fragment;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.annimon.stream.Stream;

Expand Down Expand Up @@ -85,11 +86,13 @@ private boolean onItemClick(View view, int position) {
}

private void showFlagAboutItem() {
int aboutItemPos = DrawerItem.ABOUT.ordinal();
DrawerItemFlex item = drawerAdapter.getItem(aboutItemPos);
if (item != null) {
item.setFlag(true);
drawerAdapter.notifyItemChanged(aboutItemPos);
if (drawerAdapter != null) {
int aboutItemPos = DrawerItem.ABOUT.ordinal();
DrawerItemFlex item = drawerAdapter.getItem(aboutItemPos);
if (item != null) {
item.setFlag(true);
drawerAdapter.notifyItemChanged(aboutItemPos);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(KEY_HUD_VISIBLE, controlsOverlay.getVisibility());
outState.putBoolean(KEY_GALLERY_SHOWN, hasGalleryBeenShown);
viewModel.setStartingIndex(imageIndex); // Memorize the current page
viewModel.onSaveState(outState);
}

Expand Down Expand Up @@ -194,12 +195,16 @@ else if (1.0 != scale && pageSnapWidget.isPageSnapEnabled())
});
recyclerView.setLongTapListener(ev -> false);

OnZoneTapListener onZoneTapListener = new OnZoneTapListener(recyclerView)
OnZoneTapListener onHorizontalZoneTapListener = new OnZoneTapListener(recyclerView)
.setOnLeftZoneTapListener(this::onLeftTap)
.setOnRightZoneTapListener(this::onRightTap)
.setOnMiddleZoneTapListener(this::onMiddleTap);
recyclerView.setTapListener(onZoneTapListener); // For paper roll mode (vertical)
adapter.setItemTouchListener(onZoneTapListener); // For independent images mode (horizontal)

OnZoneTapListener onVerticalZoneTapListener = new OnZoneTapListener(recyclerView)
.setOnMiddleZoneTapListener(this::onMiddleTap);

recyclerView.setTapListener(onVerticalZoneTapListener); // For paper roll mode (vertical)
adapter.setItemTouchListener(onHorizontalZoneTapListener); // For independent images mode (horizontal)

adapter.setRecyclerView(recyclerView);

Expand Down Expand Up @@ -386,6 +391,7 @@ private void onImagesChanged(List<ImageFile> images) {

maxPosition = images.size() - 1;
seekBar.setMax(maxPosition);
updatePageDisplay();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.webkit.MimeTypeMap;

import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
import androidx.core.content.FileProvider;

import java.io.File;

import me.devsaki.hentoid.R;
import me.devsaki.hentoid.util.FileHelper;
import me.devsaki.hentoid.util.notification.Notification;

public class UpdateInstallNotification implements Notification {

private final static String APK_MIMETYPE = MimeTypeMap.getSingleton().getMimeTypeFromExtension("apk");
private final Uri apkUri;

public UpdateInstallNotification(Uri apkUri) {
Expand All @@ -21,7 +29,17 @@ public UpdateInstallNotification(Uri apkUri) {
@NonNull
@Override
public android.app.Notification onCreateNotification(Context context) {
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE, apkUri);
Intent intent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
File f = new File(apkUri.getPath());
Uri contentUri = FileProvider.getUriForFile(context, FileHelper.getFileProviderAuthority(), f);
intent = new Intent(Intent.ACTION_INSTALL_PACKAGE, contentUri);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(apkUri, APK_MIMETYPE);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@
public class UpdateNotificationChannel {

private static final String ID_OLD = "update";
static final String ID = "update2";
private static final String ID_OLD2 = "update2";
static final String ID = "update3";

public static void init(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String name = "App updates";
int importance = NotificationManager.IMPORTANCE_MIN;
String name = "Updates";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(ID, name, importance);
channel.setSound(null, null);
channel.setVibrationPattern(null);

NotificationManager notificationManager = context.getSystemService(NotificationManager.class);

// Mandatory; it is not possible to change the sound of an existing channel after its initial creation
notificationManager.deleteNotificationChannel(ID_OLD);
notificationManager.deleteNotificationChannel(ID_OLD2);

Objects.requireNonNull(notificationManager).createNotificationChannel(channel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public ContentDownloadService() {
@Override
public void onCreate() {
super.onCreate();
db = ObjectBoxDB.getInstance(this);

notificationManager = new ServiceNotificationManager(this, 1);
notificationManager.cancel();
notificationManager.startForeground(new DownloadProgressNotification("Starting download", 0, 0));
Expand All @@ -98,6 +96,8 @@ public void onCreate() {

EventBus.getDefault().register(this);

db = ObjectBoxDB.getInstance(this);

Timber.d("Download service created");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ public IBinder onBind(Intent intent) {
public void onCreate() {
notificationManager = new ServiceNotificationManager(this, NOTIFICATION_ID);
notificationManager.startForeground(new UpdateCheckNotification());

Timber.w("Service created");
}

@Override
public void onDestroy() {
notificationManager.cancel();
if (disposable != null) disposable.dispose();
Timber.w("Service destroyed");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

/**
* Service responsible for downloading an update APK.
* Does not support targetSdkVersion > 23 due to exposure of "file:" URI
*
* @see UpdateCheckService
*/
Expand Down Expand Up @@ -68,7 +67,6 @@ public void onCreate() {
@Override
public void onDestroy() {
running = false;
notificationManager.cancel();
downloadManager.release();
Timber.w("Service destroyed");
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/me/devsaki/hentoid/util/FileHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@ public static void openFile(Context context, File aFile) {
}
}

public static String getFileProviderAuthority()
{
return AUTHORITY;
}

/**
* Open built-in image viewer telling it to display the images of the given Content
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import me.devsaki.hentoid.HentoidApp;
import me.devsaki.hentoid.R;
import me.devsaki.hentoid.database.ObjectBoxCollectionAccessor;
import me.devsaki.hentoid.database.ObjectBoxDB;
import me.devsaki.hentoid.database.domains.Content;
import me.devsaki.hentoid.database.domains.ImageFile;
import me.devsaki.hentoid.enums.StatusContent;
import me.devsaki.hentoid.listener.PagedResultListener;
import me.devsaki.hentoid.util.Consts;
import me.devsaki.hentoid.util.FileHelper;
Expand Down Expand Up @@ -148,8 +150,7 @@ public void onShuffleClick() {
if (imgs != null) sortAndSetImages(imgs, isShuffled);
}

private void sortAndSetImages(@Nonnull List<ImageFile> imgs, boolean shuffle)
{
private void sortAndSetImages(@Nonnull List<ImageFile> imgs, boolean shuffle) {
if (shuffle) {
Collections.shuffle(imgs);
} else {
Expand Down Expand Up @@ -245,10 +246,16 @@ private void processContent(Content theContent) {
theContent.setLast(currentContentIndex == contentIds.size() - 1);

// Load new content
File[] pictures = FileHelper.getPictureFilesFromContent(theContent);
if (pictures != null && pictures.length > 0 && theContent.getImageFiles() != null) {
List<ImageFile> imageFiles = new ArrayList<>(theContent.getImageFiles());
matchFilesToImageList(pictures, imageFiles);
File[] pictureFiles = FileHelper.getPictureFilesFromContent(theContent);
if (pictureFiles != null && pictureFiles.length > 0) {
List<ImageFile> imageFiles;
if (null == theContent.getImageFiles() || theContent.getImageFiles().isEmpty()) {
imageFiles = new ArrayList<>();
saveFilesToImageList(pictureFiles, imageFiles, theContent);
} else {
imageFiles = new ArrayList<>(theContent.getImageFiles());
matchFilesToImageList(pictureFiles, imageFiles);
}
setImages(imageFiles);

if (Preferences.isViewerResumeLastLeft()) {
Expand All @@ -272,7 +279,7 @@ private void processContent(Content theContent) {
}
}

private static void matchFilesToImageList(File[] files, List<ImageFile> images) {
private static void matchFilesToImageList(File[] files, @Nonnull List<ImageFile> images) {
int i = 0;
while (i < images.size()) {
boolean matchFound = false;
Expand All @@ -291,6 +298,21 @@ private static void matchFilesToImageList(File[] files, List<ImageFile> images)
}
}

private static void saveFilesToImageList(File[] files, @Nonnull List<ImageFile> images, @Nonnull Content content) {
int order = 0;
// Sort files by name alpha
List<File> fileList = Stream.of(files).sortBy(File::getName).collect(toList());
for (File f : fileList) {
order++;
ImageFile img = new ImageFile();
String name = FileHelper.getFileNameWithoutExtension(f.getName());
img.setName(name).setOrder(order).setUrl("").setStatus(StatusContent.DOWNLOADED).setAbsolutePath(f.getAbsolutePath());
images.add(img);
}
content.addImageFiles(images);
ObjectBoxDB.getInstance(HentoidApp.getAppContext()).insertContent(content);
}

@WorkerThread
@Nullable
private static Content postLoadProcessing(@Nonnull Context context, @Nonnull Content content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public OnZoneTapListener setOnMiddleZoneTapListener(Runnable onMiddleZoneTapList
}

public boolean onSingleTapConfirmedAction(MotionEvent e) {
if (e.getX() < pagerTapZoneWidth) {
if (e.getX() < pagerTapZoneWidth && onLeftZoneTapListener != null) {
onLeftZoneTapListener.run();
} else if (e.getX() > view.getWidth() - pagerTapZoneWidth) {
} else if (e.getX() > view.getWidth() - pagerTapZoneWidth && onRightZoneTapListener != null) {
onRightZoneTapListener.run();
} else {
onMiddleZoneTapListener.run();
if (onMiddleZoneTapListener != null) onMiddleZoneTapListener.run();
}
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/fragment_navigation_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
android:layout_width="match_parent"
android:layout_height="@dimen/drawer_image_height"
android:background="@drawable/nav_header_bg"
android:clickable="true"
android:focusable="true"
android:padding="@dimen/drawer_header_icon_padding">

<ImageView
Expand Down

0 comments on commit 72ccbac

Please sign in to comment.