Skip to content

Commit

Permalink
Java 1.8 is buggy, removing implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleker committed Jan 13, 2017
1 parent ee9da9f commit e1f6c6c
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 48 deletions.
7 changes: 0 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ android {
targetSdkVersion 25
versionCode 5
versionName "1.0.3"
jackOptions {
enabled true
}
}
buildTypes {
release {
Expand All @@ -30,10 +27,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}

buildscript {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
android:resource="@xml/provider_paths"/>
</provider>

<activity android:name=".activities.SimpleFormPostActivity"
android:exported="true" />

<meta-data
android:name="io.fabric.ApiKey"
android:value="dfe843f8af6acfe924ff6efa0c816fda4ece9f5c" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package news.androidtv.tvapprepo.fragments;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -99,8 +100,12 @@ public void onApkDownloaded(File downloadedApkFile) {
@Override
public void onApkDownloadedNougat(final File downloadedApkFile) {
Log.d(TAG, "Downloaded " + downloadedApkFile.getAbsolutePath());
new Handler(Looper.getMainLooper()).postDelayed(
() -> mApkDownloadHelper.install(downloadedApkFile), 1000 * 5);
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
mApkDownloadHelper.install(downloadedApkFile);
}
}, 1000 * 5);
}

@Override
Expand Down Expand Up @@ -277,8 +282,11 @@ public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
// Display picker
new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.dialog_theme))
.setTitle("Download which APK variant?")
.setItems(mSelectedApk.getDownloadTitleArray(), (dialog, which) -> {
download(mSelectedApk.getDownloadUrlArray()[which]);
.setItems(mSelectedApk.getDownloadTitleArray(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
download(mSelectedApk.getDownloadUrlArray()[i]);
}
})
.show();
} else {
Expand Down
105 changes: 72 additions & 33 deletions app/src/main/java/news/androidtv/tvapprepo/fragments/MainFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@

package news.androidtv.tvapprepo.fragments;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.v17.leanback.app.BackgroundManager;
import android.support.v17.leanback.app.BrowseFragment;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
Expand All @@ -40,6 +44,7 @@
import android.widget.EditText;
import android.widget.Toast;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
Expand All @@ -63,12 +68,14 @@
import news.androidtv.tvapprepo.model.SettingOption;
import news.androidtv.tvapprepo.presenters.ApkPresenter;
import news.androidtv.tvapprepo.presenters.DownloadedFilesPresenter;
import news.androidtv.tvapprepo.presenters.LauncherActivitiesPresenter;
import news.androidtv.tvapprepo.presenters.OptionsCardPresenter;
import news.androidtv.tvapprepo.utils.PackageInstallerUtils;
import tv.puppetmaster.tinydl.PackageInstaller;

public class MainFragment extends BrowseFragment {
private static final String TAG = "MainFragment";
private static final String TAG = MainFragment.class.getSimpleName();
private static final boolean DEBUG_SHOW_APKS = false;

private static final int BACKGROUND_UPDATE_DELAY = 300;
private static final int GRID_ITEM_WIDTH = 200;
Expand All @@ -93,8 +100,12 @@ public void onApkDownloaded(File downloadedApkFile) {

@Override
public void onApkDownloadedNougat(final File downloadedApkFile) {
new Handler(Looper.getMainLooper()).postDelayed(
() -> mApkDownloadHelper.install(downloadedApkFile), 1000 * 5);
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
mApkDownloadHelper.install(downloadedApkFile);
}
}, 1000 * 5);
}

@Override
Expand Down Expand Up @@ -163,7 +174,7 @@ private void loadRows() {
mApkDownloadHelper.addListener(mDownloadListener);
HeaderItem header = null;

if (getResources().getBoolean(R.bool.ENABLE_APP_REPO)) {
if (getResources().getBoolean(R.bool.ENABLE_APP_REPO) && DEBUG_SHOW_APKS) {
// Add a presenter for APKs - only if allowed
ApkPresenter cardPresenter = new ApkPresenter();
final ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
Expand All @@ -174,13 +185,16 @@ private void loadRows() {
checkForAppUpdates(apk);
}
}
RepoDatabase.getInstance().addListener((apk, index) -> {
Log.d(TAG, apk.getPackageName() + " " + Utils.class.getPackage().getName());
if (apk.getPackageName().equals(Utils.class.getPackage().getName())) {
checkForAppUpdates(apk);
} else {
listRowAdapter.add(apk);
listRowAdapter.notifyArrayItemRangeChanged(index, 1);
RepoDatabase.getInstance().addListener(new RepoDatabase.Listener() {
@Override
public void onApkAdded(Apk apk, int index) {
Log.d(TAG, apk.getPackageName() + " " + Utils.class.getPackage().getName());
if (apk.getPackageName().equals(Utils.class.getPackage().getName())) {
checkForAppUpdates(apk);
} else {
listRowAdapter.add(apk);
listRowAdapter.notifyArrayItemRangeChanged(index, 1);
}
}
});
header = new HeaderItem(0, getString(R.string.header_browse));
Expand All @@ -205,43 +219,62 @@ private void loadRows() {

downloadedFilesList = getApkDownloads(downloadedFilesList, myDownloads.listFiles());

// Now sort
// Now sort
Collections.sort(downloadedFilesList, (o1, o2) ->
(int) (o2.lastModified() - o1.lastModified()));
downloadedFilesAdapter.addAll(0, downloadedFilesList);
HeaderItem downloadedFilesHeader = new HeaderItem(1, getString(R.string.header_downloaded_apks));
mRowsAdapter.add(new ListRow(downloadedFilesHeader, downloadedFilesAdapter));
}

// Add a row for Leanback shortcuts
List<ResolveInfo> launcherActivities = getActivity().getPackageManager()
.queryIntentActivities(new Intent(Intent.CATEGORY_LAUNCHER), PackageManager.MATCH_ALL);
// TODO Filter out those where shortcuts already exist
LauncherActivitiesPresenter launcherActivitiesPresenter = new LauncherActivitiesPresenter();
ArrayObjectAdapter launcherActivitiesAdapter = new ArrayObjectAdapter(launcherActivitiesPresenter);
launcherActivitiesAdapter.addAll(0, launcherActivities);
HeaderItem launcherActivitiesHeader = new HeaderItem(2, "Need Shortcuts");
mRowsAdapter.add(new ListRow(launcherActivitiesHeader, launcherActivitiesAdapter));

// Add a row for credits
OptionsCardPresenter optionsCardPresenter = new OptionsCardPresenter();
ArrayObjectAdapter optionsRowAdapter = new ArrayObjectAdapter(optionsCardPresenter);
if (getResources().getBoolean(R.bool.ENABLE_SIDELOADTAG)) {
optionsRowAdapter.add(new SettingOption(
getResources().getDrawable(R.drawable.sideloadtag),
getString(R.string.install_through_sideloadtag),
() -> {
new MaterialDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.dialog_theme))
.title(R.string.sideloadtag)
.customView(R.layout.dialog_sideload_tag, false)
.onPositive((dialog, which) -> {
String tag = ((EditText) dialog.getCustomView().findViewById(R.id.tag)).getText().toString();
PackageInstaller.initialize(getActivity()).wget("http://tinyurl.com/" + tag);
Toast.makeText(getActivity(), R.string.starting_download, Toast.LENGTH_SHORT).show();
})
.positiveText(R.string.Download)
.show();
new SettingOption.OnClickListener() {
@Override
public void onClick() {
new MaterialDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.dialog_theme))
.title(R.string.sideloadtag)
.customView(R.layout.dialog_sideload_tag, false)
.onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
String tag = ((EditText) dialog.getCustomView().findViewById(R.id.tag)).getText().toString();
PackageInstaller.initialize(getActivity()).wget("http://tinyurl.com/" + tag);
Toast.makeText(getActivity(), R.string.starting_download, Toast.LENGTH_SHORT).show();
}
})
.positiveText(R.string.Download)
.show();
}
}
));
}
optionsRowAdapter.add(new SettingOption(
getResources().getDrawable(R.drawable.about_credits),
getString(R.string.credits),
() -> {
new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.dialog_theme))
.setTitle(R.string.credits)
.setMessage(R.string.about_app)
.show();
new SettingOption.OnClickListener() {
@Override
public void onClick() {
new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.dialog_theme))
.setTitle(R.string.credits)
.setMessage(R.string.about_app)
.show();
}
}
));
header = new HeaderItem(2, getString(R.string.header_more));
Expand Down Expand Up @@ -316,9 +349,12 @@ private void checkForAppUpdates(Apk apk) {
checkedForUpdates = true;
new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.dialog_theme))
.setTitle(R.string.update_for_tv_app_repo)
.setPositiveButton(R.string.update, (dialog, which) ->
.setPositiveButton(R.string.update, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
mApkDownloadHelper.startDownload(apk.getDefaultDownloadUrl())
)
}
}
.show();
}
}
Expand Down Expand Up @@ -361,9 +397,12 @@ public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
private class UpdateBackgroundTask extends TimerTask {
@Override
public void run() {
mHandler.post(() -> {
if (mBackgroundURI != null) {
updateBackground(mBackgroundURI.toString());
mHandler.post(new Runnable() {
@Override
public void run() {
if (mBackgroundURI != null) {
updateBackground(mBackgroundURI.toString());
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package news.androidtv.tvapprepo.presenters;

import android.support.v17.leanback.widget.ImageCardView;
import android.support.v17.leanback.widget.Presenter;
import android.view.ContextThemeWrapper;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.io.File;

import news.androidtv.tvapprepo.R;

/**
* A presenter which can be used to show downloaded APKs with an optional title along the bottom.
*
* @author Nick
* @version 2017.01.12
*/
public class LauncherActivitiesPresenter extends CardPresenter {
private ContextThemeWrapper contextThemeWrapper;

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
if (contextThemeWrapper == null) {
contextThemeWrapper = new ContextThemeWrapper(parent.getContext(),
R.style.OptionsImageCardViewStyle);
}
ImageCardView cardView = new ImageCardView(contextThemeWrapper);
cardView.setFocusable(true);
cardView.setFocusableInTouchMode(true);
cardView.setBackgroundColor(parent.getResources().getColor(R.color.primaryDark));
return new ViewHolder(cardView);
}

@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
final File downloadedApk = (File) item;
final ImageCardView cardView = (ImageCardView) viewHolder.view;
cardView.setMainImage(contextThemeWrapper.getDrawable(R.drawable.download));
cardView.setTitleText(downloadedApk.getName());
cardView.setMainImageDimensions(CARD_WIDTH, CARD_HEIGHT);
cardView.getMainImageView().setScaleType(ImageView.ScaleType.FIT_CENTER);
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.2.+'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Sep 21 00:24:52 EDT 2016
#Thu Jan 12 18:08:02 EST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2-all.zip
2 changes: 1 addition & 1 deletion python/Shortcut/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:2.3.0-alpha3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down

0 comments on commit e1f6c6c

Please sign in to comment.