Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using view as Snackbar container instead android.R.id.content. #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;

import com.github.javiersantos.appupdater.enums.AppUpdaterError;
import com.github.javiersantos.appupdater.enums.Display;
Expand All @@ -20,6 +21,7 @@
import com.github.javiersantos.appupdater.objects.Update;

public class AppUpdater implements IAppUpdater {
private View view;
private Context context;
private LibraryPreferences libraryPreferences;
private Display display;
Expand Down Expand Up @@ -76,6 +78,12 @@ public AppUpdater setDuration(Duration duration) {
return this;
}

@Override
public AppUpdater setView(View view) {
this.view = view;
return this;
}

@Override
public AppUpdater setGitHubUserAndRepo(@NonNull String user, @NonNull String repo) {
this.gitHub = new GitHub(user, repo);
Expand Down Expand Up @@ -348,7 +356,7 @@ public void onSuccess(Update update) {
alertDialog.show();
break;
case SNACKBAR:
snackbar = UtilsDisplay.showUpdateAvailableSnackbar(context, getDescriptionUpdate(context, update, Display.SNACKBAR), UtilsLibrary.getDurationEnumToBoolean(duration), updateFrom, update.getUrlToDownload());
snackbar = UtilsDisplay.showUpdateAvailableSnackbar(view, getDescriptionUpdate(context, update, Display.SNACKBAR), UtilsLibrary.getDurationEnumToBoolean(duration), updateFrom, update.getUrlToDownload());
snackbar.show();
break;
case NOTIFICATION:
Expand All @@ -365,7 +373,7 @@ public void onSuccess(Update update) {
alertDialog.show();
break;
case SNACKBAR:
snackbar = UtilsDisplay.showUpdateNotAvailableSnackbar(context, getDescriptionNoUpdate(context), UtilsLibrary.getDurationEnumToBoolean(duration));
snackbar = UtilsDisplay.showUpdateNotAvailableSnackbar(view, getDescriptionNoUpdate(context), UtilsLibrary.getDurationEnumToBoolean(duration));
snackbar.show();
break;
case NOTIFICATION:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.javiersantos.appupdater;

import android.app.Activity;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
Expand Down Expand Up @@ -38,8 +37,8 @@ public void onClick(DialogInterface dialogInterface, int i) {}
.create();
}

static Snackbar showUpdateAvailableSnackbar(final Context context, String content, Boolean indefinite, final UpdateFrom updateFrom, final URL apk) {
Activity activity = (Activity) context;
static Snackbar showUpdateAvailableSnackbar(View view, String content, Boolean indefinite, final UpdateFrom updateFrom, final URL apk) {
final Context context = view.getContext();
int snackbarTime = indefinite ? Snackbar.LENGTH_INDEFINITE : Snackbar.LENGTH_LONG;

/*if (indefinite) {
Expand All @@ -48,7 +47,7 @@ static Snackbar showUpdateAvailableSnackbar(final Context context, String conten
snackbarTime = Snackbar.LENGTH_LONG;
}*/

Snackbar snackbar = Snackbar.make(activity.findViewById(android.R.id.content), content, snackbarTime);
Snackbar snackbar = Snackbar.make(view, content, snackbarTime);
snackbar.setAction(context.getResources().getString(R.string.appupdater_btn_update), new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -58,8 +57,7 @@ public void onClick(View view) {
return snackbar;
}

static Snackbar showUpdateNotAvailableSnackbar(final Context context, String content, Boolean indefinite) {
Activity activity = (Activity) context;
static Snackbar showUpdateNotAvailableSnackbar(View view, String content, Boolean indefinite) {
int snackbarTime = indefinite ? Snackbar.LENGTH_INDEFINITE : Snackbar.LENGTH_LONG;

/*if (indefinite) {
Expand All @@ -69,7 +67,7 @@ static Snackbar showUpdateNotAvailableSnackbar(final Context context, String con
}*/


return Snackbar.make(activity.findViewById(android.R.id.content), content, snackbarTime);
return Snackbar.make(view, content, snackbarTime);
}

static void showUpdateAvailableNotification(Context context, String title, String content, UpdateFrom updateFrom, URL apk, int smallIconResourceId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.view.View;

import com.github.javiersantos.appupdater.AppUpdater;
import com.github.javiersantos.appupdater.DisableClickListener;
Expand Down Expand Up @@ -43,6 +44,15 @@ public interface IAppUpdater {
*/
AppUpdater setDuration(Duration duration);


/**
* Set the view where Snackbar will be placed.
*
* @param view view where Snackbar will be placed.
* @return this
*/
AppUpdater setView(View view);

/**
* Set the user and repo where the releases are uploaded. You must upload your updates as a release in order to work properly tagging them as vX.X.X or X.X.X.
*
Expand Down