Skip to content

Commit

Permalink
Merge pull request #54 from Fleker/master
Browse files Browse the repository at this point in the history
Fixes a bug where web shortcuts may not generate
  • Loading branch information
Fleker committed Oct 9, 2017
2 parents 4cf8344 + 7f47695 commit b0abb65
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 41 deletions.
27 changes: 15 additions & 12 deletions app/build.gradle
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "news.androidtv.tvapprepo"
minSdkVersion 21
targetSdkVersion 25
versionCode 15
versionName "1.1.2"
versionCode 16
versionName "1.1.3"
}
buildTypes {
release {
Expand Down Expand Up @@ -48,21 +48,24 @@ repositories {
maven { url 'https://maven.fabric.io/public' }
}

ext {
supportLibrary = '25.3.1'
googlePlayServices = '11.2.0'
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.android.support:leanback-v17:25.1.0'
compile 'com.android.support:preference-leanback-v17:25.1.0'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:palette-v7:25.1.0'
compile "com.android.support:recyclerview-v7:$project.ext.supportLibrary"
compile "com.android.support:leanback-v17:$project.ext.supportLibrary"
compile "com.android.support:preference-leanback-v17:$project.ext.supportLibrary"
compile "com.android.support:appcompat-v7:$project.ext.supportLibrary"
compile "com.android.support:palette-v7:$project.ext.supportLibrary"

compile 'com.google.firebase:firebase-database:10.0.1'
compile 'com.google.android.gms:play-services-ads:10.0.1'
compile 'com.google.firebase:firebase-config:10.0.1'
compile 'com.google.firebase:firebase-ads:10.0.1'
compile "com.google.firebase:firebase-database:$project.ext.googlePlayServices"
compile "com.google.android.gms:play-services-ads:$project.ext.googlePlayServices"
compile "com.google.firebase:firebase-config:$project.ext.googlePlayServices"
compile "com.google.firebase:firebase-ads:$project.ext.googlePlayServices"

// compile 'com.colortv:android-sdk:2.1.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.afollestad.material-dialogs:core:0.9.0.2'
compile 'com.android.volley:volley:1.0.0'
Expand Down
Expand Up @@ -109,13 +109,15 @@ public void onClick(View v) {
}

private void publish() {
advancedOptions.updateContext(this); // We pass in a new context for this activity.
boolean isGame = ((Switch) findViewById(R.id.switch_isgame)).isChecked();
String bannerUrl =
((EditText) findViewById(R.id.edit_banner)).getText().toString();
if (!bannerUrl.isEmpty()) {
advancedOptions.setBannerUrl(bannerUrl);
}
advancedOptions.setIsGame(isGame);
Log.d(TAG, "Sending form data to GenerateShortcutHelper");
GenerateShortcutHelper.generateShortcut(this, resolveInfo, advancedOptions);
}

Expand All @@ -126,7 +128,7 @@ private void loadCustomIconography() {
resolveInfo.activityInfo.name), callback);

} else {
Toast.makeText(this, "Cannot set banner of non-app yet", Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.warning_no_banners_available, Toast.LENGTH_SHORT).show();
}
}
}
Expand Up @@ -7,6 +7,7 @@
import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

import com.bumptech.glide.Glide;

Expand All @@ -22,6 +23,8 @@
* Created by Nick on 3/20/2017. A model for storing advanced options in generating shortcuts.
*/
public class AdvancedOptions implements Parcelable {
private static final String TAG = AdvancedOptions.class.getSimpleName();

private volatile int mReady = 0;
private String mCategory = "";
private String mIconUrl = "";
Expand Down Expand Up @@ -115,6 +118,11 @@ public AdvancedOptions setIconBitmap(Bitmap bitmap) {
return this;
}

public void updateContext(Context context) {
// Swap out contexts.
this.mContext = context;
}

public boolean isReady() {
return mReady == 0;
}
Expand Down Expand Up @@ -156,6 +164,9 @@ private void downloadBanner(final Context context, final String url, final Glide
@Override
public void run() {
try {
if (context == null) {
throw new NullPointerException("Context is null");
}
Bitmap bitmap = Glide.with(context).load(url).asBitmap().into(320, 180).get();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
Expand Down
Expand Up @@ -37,11 +37,16 @@ public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which)
}
String label = tag.replaceAll("(http://)|(https://)", "");
Log.d(TAG, IntentUriGenerator.generateWebBookmark(tag));
AdvancedOptions options = new AdvancedOptions(activity)
.setIntentUri(IntentUriGenerator.generateWebBookmark(tag))
.setIconUrl("https://raw.githubusercontent.com/ITVlab/TvAppRepo/master/promo/graphics/icon.png") // TODO Replace icon url
.setCustomLabel(label);
GenerateShortcutHelper.begin(activity, label, options);
try {
AdvancedOptions options = new AdvancedOptions(activity)
.setIntentUri(IntentUriGenerator.generateWebBookmark(tag))
.setIconUrl("https://raw.githubusercontent.com/ITVlab/TvAppRepo/master/promo/graphics/icon.png") // TODO Replace icon url
.setCustomLabel(label);
GenerateShortcutHelper.begin(activity, label, options);
} catch (AdvancedOptions.StringLengthException exception) {
Toast.makeText(activity, exception.getMessage(), Toast.LENGTH_SHORT)
.show();
}
}
})
.positiveText(R.string.generate_shortcut)
Expand Down
Expand Up @@ -138,6 +138,7 @@ public static void generateShortcut(final Activity activity, final ResolveInfo r
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
Log.d(TAG, "Delaying until web ops are complete");
generateShortcut(activity, resolveInfo, options);
}
}, 200);
Expand Down
Expand Up @@ -2,29 +2,21 @@

import android.content.Context;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Network;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.Volley;
import com.bumptech.glide.Glide;
import com.sketchproject.infogue.modules.VolleyMultipartRequest;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;

import news.androidtv.tvapprepo.R;
import news.androidtv.tvapprepo.model.AdvancedOptions;
Expand Down Expand Up @@ -123,16 +115,21 @@ protected Map<String, DataPart> getByteData() {
// file name could found file base or direct access from real path
// for now just get bitmap data from ImageView
if (options.getIcon() != null) {
params.put(FORM_APP_LOGO, new DataPart("file_avatar.png", options.getIcon(),
params.put(FORM_APP_LOGO, new DataPart("file_logo.png", options.getIcon(),
"image/png"));
} else if (app != null) {
params.put(FORM_APP_LOGO, new DataPart("file_avatar.png",
VolleyMultipartRequest.getFileDataFromDrawable(context,
app.activityInfo.loadIcon(context.getPackageManager())),
"image/png"));
try {
byte[] imageData = VolleyMultipartRequest.getFileDataFromDrawable(context,
app.activityInfo.loadIcon(context.getPackageManager()));
params.put(FORM_APP_LOGO, new DataPart("file_logo.png", imageData,
"image/png"));
} catch (ClassCastException e) {
Toast.makeText(context, R.string.error_getting_logo,
Toast.LENGTH_SHORT).show();
}
}
if (options.getBanner() != null) {
params.put(FORM_APP_BANNER, new DataPart("file_avatar.png", options.getBanner(),
params.put(FORM_APP_BANNER, new DataPart("file_banner.png", options.getBanner(),
"image/png"));
}
return params;
Expand Down
Expand Up @@ -285,11 +285,12 @@ protected Integer doInBackground(String... urls) {
(DownloadManager) mActivity.getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
} catch (Exception e) {
Toast.makeText(mActivity.getApplicationContext(), e.getMessage(),
String errorMsg = e.getMessage() + ": " + downloadedFileName + ", " +
urls[0] + ", " + DOWNLOADS_DIRECTORY.toString();
Toast.makeText(mActivity.getApplicationContext(), errorMsg,
Toast.LENGTH_SHORT).show();
// Tell user about an error and throw with additional debug info.
throw new RuntimeException(e.getMessage() + ": " + downloadedFileName + ", " +
urls[0] + ", " + DOWNLOADS_DIRECTORY.toString());
throw new RuntimeException(errorMsg);
}
Log.i(TAG, "Download request for " + urls[0] + " enqueued");
Log.d(TAG, "Should be saved to " + downloadedFileName);
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/layout/activity_advanced.xml
Expand Up @@ -25,11 +25,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"></LinearLayout>
</ScrollView>

<EditText
android:id="@+id/edit_banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Banner URL (Optional)"
android:id="@+id/edit_banner"
android:layout_height="wrap_content" />
android:inputType="textUri|textWebEditText" />
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="16dp"
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Expand Up @@ -77,5 +77,7 @@
<string name="advanced_options">Advanced Options</string>
<string name="msg_pls_wait">Please wait. This may take up to 20 seconds.</string>
<string name="generate_file_shortcut">File Link</string>

<string name="error_getting_logo" translatable="false">Error - Volley cannot get file data for app icon</string>
<string name="warning_no_banners_available" translatable="false">Cannot find custom banner packs for non-apps</string>

</resources>
7 changes: 5 additions & 2 deletions build.gradle
Expand Up @@ -5,8 +5,8 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.+'
classpath 'com.google.gms:google-services:3.0.0'
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.google.gms:google-services:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -15,6 +15,9 @@ buildscript {
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}

Expand Down

0 comments on commit b0abb65

Please sign in to comment.