diff --git a/.circleci/config.yml b/.circleci/config.yml index d946ede..b1b77ea 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -50,7 +50,7 @@ jobs: - run: name: "Publish Release on GitHub" command: | - VERSION=v1.5.3 + VERSION=v2.0.0-alpha1 ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} androidbasichelperlib/build/outputs/artifacts workflows: version: 2 diff --git a/androidbasichelperlib/build.gradle b/androidbasichelperlib/build.gradle index 6b01ab0..09184a8 100644 --- a/androidbasichelperlib/build.gradle +++ b/androidbasichelperlib/build.gradle @@ -21,8 +21,8 @@ android { dependencies { // testImplementation "junit:junit:4.12" - testImplementation "org.robolectric:robolectric:4.1" - testImplementation "com.squareup.okhttp3:mockwebserver:3.12.1" + testImplementation "org.robolectric:robolectric:4.2" + testImplementation "com.squareup.okhttp3:mockwebserver:3.13.1" testImplementation "androidx.test:core:1.1.0" testImplementation 'androidx.test:runner:1.1.1' testImplementation 'androidx.test:rules:1.1.1' @@ -33,18 +33,26 @@ dependencies { }) testImplementation "androidx.test.espresso:espresso-intents:3.1.1" testImplementation "com.google.code.findbugs:jsr305:3.0.2" - testImplementation "org.mockito:mockito-core:2.23.4" + testImplementation "org.mockito:mockito-core:2.25.0" // testImplementation "androidx.arch.core:core-testing:2.0.0" // testImplementation "org.mockito:mockito-core:2.23.4" implementation 'com.google.android.material:material:1.0.0' - api 'com.afollestad.material-dialogs:core:0.9.6.0' - api 'com.afollestad.material-dialogs:commons:0.9.6.0' + + api 'com.afollestad.material-dialogs:core:2.6.0' + api 'com.afollestad.material-dialogs:input:2.6.0' + api 'com.afollestad.material-dialogs:files:2.6.0' + api 'com.afollestad.material-dialogs:color:2.6.0' + api 'com.afollestad.material-dialogs:datetime:2.6.0' + api 'com.afollestad.material-dialogs:lifecycle:2.6.0' + api 'com.joanzapata.iconify:android-iconify-fontawesome:2.2.2' + api 'com.code-troopers.betterpickers:library:3.1.0' - implementation 'com.blankj:utilcode:1.9.8' + + implementation 'com.blankj:utilcode:1.14.1' implementation "androidx.core:core-ktx:1.0.1" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" } \ No newline at end of file diff --git a/androidbasichelperlib/src/main/java/com/aykuttasil/androidbasichelperlib/UiHelper.java b/androidbasichelperlib/src/main/java/com/aykuttasil/androidbasichelperlib/UiHelper.java deleted file mode 100644 index 5f73fab..0000000 --- a/androidbasichelperlib/src/main/java/com/aykuttasil/androidbasichelperlib/UiHelper.java +++ /dev/null @@ -1,398 +0,0 @@ -package com.aykuttasil.androidbasichelperlib; - -import android.content.Context; -import android.graphics.Color; -import android.graphics.drawable.Drawable; -import androidx.coordinatorlayout.widget.CoordinatorLayout; -import com.google.android.material.snackbar.Snackbar; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewParent; -import android.widget.FrameLayout; -import android.widget.TextView; -import android.widget.Toast; - -import com.afollestad.materialdialogs.DialogAction; -import com.afollestad.materialdialogs.MaterialDialog; -import com.joanzapata.iconify.IconDrawable; -import com.joanzapata.iconify.Iconify; -import com.joanzapata.iconify.fonts.FontAwesomeIcons; -import com.joanzapata.iconify.fonts.FontAwesomeModule; - -public class UiHelper { - - public static class UiDialog { - - MaterialDialog dialog; - MaterialDialog.Builder mBuilder; - Context mContext; - - private UiDialog(Context context) { - Iconify.with(new FontAwesomeModule()); - mContext = context; - mBuilder = new MaterialDialog.Builder(context); - dialog = new MaterialDialog.Builder(context).build(); - } - - public static UiDialog newInstance(Context context) { - return new UiDialog(context); - } - - public MaterialDialog getMaterialDialog() { - return dialog; - } - - public MaterialDialog.Builder getMaterialDialogBuilder() { - return mBuilder; - } - - public static void showSimpleDialog(Context context, String title, String message) { - newInstance(context).getMaterialDialogBuilder().title(title).content(message).autoDismiss(true).build().show(); - - } - - public MaterialDialog getIndeterminateDialog(String title, String content) { - return mBuilder - .title(title) - .content(content) - .progress(true, 100, false) - .progressIndeterminateStyle(true) - .cancelable(false) - .icon(new IconDrawable(mContext, FontAwesomeIcons.fa_comment).actionBarSize().color(Color.GRAY)) - .build(); - } - - public MaterialDialog getOKDialog(String title, String content, Drawable icon) { - return mBuilder - .title(title) - .content(content) - .cancelable(false) - .icon(icon == null ? new IconDrawable(mContext, FontAwesomeIcons.fa_angle_right).actionBarSize().color(Color.GRAY) : icon) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(MaterialDialog dialog, DialogAction which) { - dialog.dismiss(); - } - }) - .positiveText("Devam Et") - .build(); - } - - public MaterialDialog getOKCancelDialog(String title, String content, Drawable icon) { - return mBuilder - .title(title) - .content(content) - .cancelable(false) - .icon(icon == null ? new IconDrawable(mContext, FontAwesomeIcons.fa_angle_right).actionBarSize().color(Color.GRAY) : icon) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(MaterialDialog dialog, DialogAction which) { - dialog.dismiss(); - } - }) - .onNegative(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(MaterialDialog dialog, DialogAction which) { - dialog.dismiss(); - } - }) - .negativeText("İptal Et") - .positiveText("Devam Et") - .negativeColor(Color.GRAY) - .positiveColor(mContext.getResources().getColor(R.color.accent)) - .build(); - } - - public MaterialDialog getProgressDialog(String title, String content, Drawable icon) { - return mBuilder - .title(title) - .content(content) - .cancelable(false) - .icon(icon == null ? new IconDrawable(mContext, FontAwesomeIcons.fa_angle_right).actionBarSize().color(Color.GRAY) : icon) - .progress(true, 0) - .build(); - } - - public MaterialDialog getProgressDialog(String content, Drawable icon) { - return mBuilder - .content(content) - .cancelable(false) - .icon(icon == null ? new IconDrawable(mContext, FontAwesomeIcons.fa_angle_right).actionBarSize().color(Color.GRAY) : icon) - .progress(true, 0) - .build(); - } - } - -// public static class UiSweetDialog { -// -// Context mContext; -// SweetAlertDialog mSweetAlertDialog; -// -// private UiSweetDialog(Context context, int alertDialogType) { -// Iconify.with(new FontAwesomeModule()); -// mContext = context; -// mSweetAlertDialog = new SweetAlertDialog(context, alertDialogType); -// } -// -// public static UiSweetDialog newInstance(Context context, int alertDialogType) { -// return new UiSweetDialog(context, alertDialogType); -// } -// -// public SweetAlertDialog getMaterialDialog() { -// try { -// if (mSweetAlertDialog == null) { -// throw new Exception("mSweetAlertDialog is null"); -// } -// } catch (Exception e) { -// e.printStackTrace(); -// } -// return mSweetAlertDialog; -// } -// -// public static void showSimpleDialog(Context context, String title, String message) { -// -// newInstance(context, SweetAlertDialog.NORMAL_TYPE).mSweetAlertDialog.setTitleText(title).setContentText(message).show(); -// -// } -// -// public SweetAlertDialog getIndeterminateDialog(String title, String content) { -// return mBuilder -// .title(title) -// .content(content) -// .progress(true, 100, false) -// .progressIndeterminateStyle(true) -// .cancelable(false) -// .icon(new IconDrawable(mContext, FontAwesomeIcons.fa_comment).actionBarSize().color(Color.GRAY)) -// .build(); -// } -// -// public SweetAlertDialog getOKDialog(String title, String content, Drawable icon) { -// return mBuilder -// .title(title) -// .content(content) -// .cancelable(false) -// .icon(icon == null ? new IconDrawable(mContext, FontAwesomeIcons.fa_angle_right).actionBarSize().color(Color.GRAY) : icon) -// .onPositive(new MaterialDialog.SingleButtonCallback() { -// @Override -// public void onClick(MaterialDialog dialog, DialogAction which) { -// dialog.dismiss(); -// } -// }) -// .positiveText("Devam Et") -// .build(); -// } -// -// public SweetAlertDialog getOKCancelDialog(final String title, String content, final String whenClickOkText, Drawable icon) { -// -// mSweetAlertDialog.setTitleText(title); -// mSweetAlertDialog.setContentText(content); -// mSweetAlertDialog.setCancelable(false); -// mSweetAlertDialog.setCustomImage(icon); -// mSweetAlertDialog.setCancelText("İptal Et"); -// mSweetAlertDialog.setConfirmText("Devam et"); -// -// mSweetAlertDialog.setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() { -// @Override -// public void onClick(SweetAlertDialog sweetAlertDialog) { -// sweetAlertDialog.dismiss(); -// } -// }); -// -// mSweetAlertDialog.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { -// @Override -// public void onClick(SweetAlertDialog sweetAlertDialog) { -// sweetAlertDialog -// .setTitleText(title) -// .setContentText(whenClickOkText) -// .showCancelButton(false) -// .setConfirmText("Tamam") -// .setConfirmClickListener(null) -// .changeAlertType(SweetAlertDialog.SUCCESS_TYPE); -// } -// }); -// -// mSweetAlertDialog.show(); -// -// return mSweetAlertDialog; -// -// -// return mBuilder -// .title(title) -// .content(content) -// .cancelable(false) -// .icon(icon == null ? new IconDrawable(mContext, FontAwesomeIcons.fa_angle_right).actionBarSize().color(Color.GRAY) : icon) -// .onPositive(new MaterialDialog.SingleButtonCallback() { -// @Override -// public void onClick(MaterialDialog dialog, DialogAction which) { -// dialog.dismiss(); -// } -// }) -// .onNegative(new MaterialDialog.SingleButtonCallback() { -// @Override -// public void onClick(MaterialDialog dialog, DialogAction which) { -// dialog.dismiss(); -// } -// }) -// .negativeText("İptal Et") -// .positiveText("Devam Et") -// .negativeColor(Color.GRAY) -// .positiveColor(mContext.getResources().getColor(R.color.accent)) -// .build(); -// } -// -// public SweetAlertDialog getProgressDialog(String title, String content, Drawable icon) { -// -// mSweetAlertDialog.setTitleText(title); -// mSweetAlertDialog.setContentText(content); -// mSweetAlertDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86")); -// mSweetAlertDialog.setCancelable(false); -// mSweetAlertDialog.show(); -// -// return mSweetAlertDialog; -// } -// -// public SweetAlertDialog getProgressDialog(String content, Drawable icon) { -// -// mSweetAlertDialog.setContentText(content); -// mSweetAlertDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86")); -// mSweetAlertDialog.setCancelable(false); -// mSweetAlertDialog.show(); -// -// return mSweetAlertDialog; -// } -// } - - public static class UiSnackBar { - Snackbar snackbar; - - private UiSnackBar(View view, String text, int duration) { - snackbar = Snackbar.make(view, text, duration); - } - - public static Snackbar newInstance(View view, String text, int duration) { - return new UiSnackBar(view, text, duration).snackbar; - } - - public static UiSnackBar newInstance(Context context, View view) { - return new UiSnackBar(view, null, Snackbar.LENGTH_LONG); - } - - public static void showSimpleSnackBar(View view, String text, int duration) { - if (view == null) return; - - Snackbar snackbar = Snackbar.make(view, text, duration); - TextView textView = snackbar.getView().findViewById(R.id.snackbar_text); - textView.setTextColor(Color.WHITE); - - snackbar.show(); - } - - private static ViewGroup findSuitableParent(View view) { - ViewGroup fallback = null; - do { - if (view instanceof CoordinatorLayout) { - // We've found a CoordinatorLayout, use it - return (ViewGroup) view; - } else if (view instanceof FrameLayout) { - if (view.getId() == android.R.id.content) { - // If we've hit the decor content view, then we didn't find a CoL in the - // hierarchy, so use it. - return (ViewGroup) view; - } else { - // It's not the content view but we'll use it as our fallback - fallback = (ViewGroup) view; - } - } - - if (view != null) { - // Else, we will loop and crawl up the view hierarchy and try to find a parent - final ViewParent parent = view.getParent(); - view = parent instanceof View ? (View) parent : null; - } - } while (view != null); - - // If we reach here then we didn't find a CoL or a suitable content view so we'll fallback - return fallback; - } - - public UiSnackBar setText(String text) { - snackbar.setText(text); - return this; - } - - public UiSnackBar setDuration(int duration) { - snackbar.setDuration(duration); - return this; - } - - public UiSnackBar setBackgroundColor(int color) { - snackbar.getView().setBackgroundColor(color); - return this; - } - - public UiSnackBar setActionTextColor(int color) { - snackbar.setActionTextColor(color); - return this; - } - - public UiSnackBar setMessageTextColor(int color) { - TextView textView = (TextView) snackbar.getView().findViewById(R.id.snackbar_text); - textView.setTextColor(color); - return this; - } - - public Snackbar getSnackbar() { - return snackbar; - } - - public void show() { - snackbar.show(); - } - - } - - public static class UiToast { - - static Context mContext; - Toast toast; - - private UiToast(Context context, String text, int duration) { - mContext = context; - toast = Toast.makeText(context, text, duration); - - } - - public static Toast newInstance(Context context, String text, int duration) { - mContext = context; - return new UiToast(context, text, duration).toast; - } - - public static UiToast newInstance(Context context) { - return new UiToast(context, null, Toast.LENGTH_LONG); - } - - public static void showSimpleToast(Context context, String text, int duration) { - Toast.makeText(context, text, duration).show(); - - } - - public UiToast setText(String text) { - toast.setText(text); - return this; - } - - public UiToast setDuration(int duration) { - toast.setDuration(duration); - return this; - } - - public UiToast setBackgroundColor(int color) { - toast.getView().setBackgroundColor(color); - return this; - } - - public void show() { - toast.show(); - } - } -} diff --git a/androidbasichelperlib/src/main/java/com/aykuttasil/androidbasichelperlib/UiHelper.kt b/androidbasichelperlib/src/main/java/com/aykuttasil/androidbasichelperlib/UiHelper.kt new file mode 100644 index 0000000..55890fa --- /dev/null +++ b/androidbasichelperlib/src/main/java/com/aykuttasil/androidbasichelperlib/UiHelper.kt @@ -0,0 +1,379 @@ +package com.aykuttasil.androidbasichelperlib + +import android.content.Context +import android.graphics.Color +import android.graphics.drawable.Drawable +import android.view.View +import android.view.ViewGroup +import android.widget.FrameLayout +import android.widget.TextView +import android.widget.Toast +import androidx.coordinatorlayout.widget.CoordinatorLayout +import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.customview.customView +import com.afollestad.materialdialogs.customview.getCustomView +import com.google.android.material.snackbar.Snackbar +import com.joanzapata.iconify.IconDrawable +import com.joanzapata.iconify.Iconify +import com.joanzapata.iconify.fonts.FontAwesomeIcons +import com.joanzapata.iconify.fonts.FontAwesomeModule + +class UiHelper { + + class UiDialog private constructor(var mContext: Context) { + + var materialDialog: MaterialDialog + + init { + Iconify.with(FontAwesomeModule()) + materialDialog = MaterialDialog(mContext) + } + + @JvmOverloads + fun getIndeterminateDialog(title: String, content: String = "Lütfen Bekleyiniz..."): MaterialDialog { + val dialog = MaterialDialog(mContext) + .title(text = title) + .message(text = content) + .customView(viewRes = R.layout.progress_dialog_horizontal_layout) + .cancelable(false) + + return dialog + } + + fun getOKDialog(title: String, content: String, icon: Drawable?): MaterialDialog { + return materialDialog + .title(text = title) + .message(text = content) + .cancelable(false) + .icon(drawable = icon + ?: IconDrawable(mContext, FontAwesomeIcons.fa_angle_right).actionBarSize().color(Color.GRAY)) + .positiveButton(text = "Devam Et") { dialog -> + dialog.dismiss() + } + } + + fun getOKCancelDialog(title: String, content: String, icon: Drawable?): MaterialDialog { + return materialDialog + .title(text = title) + .message(text = content) + .cancelable(false) + .icon(drawable = icon + ?: IconDrawable(mContext, FontAwesomeIcons.fa_angle_right).actionBarSize().color(Color.GRAY)) + .positiveButton(text = "Devam Et") { dialog -> + dialog.dismiss() + } + + .negativeButton(text = "İptal Et") { dialog -> + dialog.dismiss() + } + } + + fun getProgressDialog(title: String, content: String, icon: Drawable?): MaterialDialog { + val dialog = materialDialog + .title(text = title) + .cancelable(false) + .icon(drawable = icon + ?: IconDrawable(mContext, FontAwesomeIcons.fa_angle_right).actionBarSize().color(Color.GRAY)) + .customView(viewRes = R.layout.progress_dialog_layout) + + dialog.getCustomView().findViewById(R.id.txtContent).text = content + return dialog + } + + + fun getProgressDialog(content: String, icon: Drawable?): MaterialDialog { + val dialog = materialDialog + .cancelable(false) + .icon(drawable = icon + ?: IconDrawable(mContext, FontAwesomeIcons.fa_angle_right).actionBarSize().color(Color.GRAY)) + + dialog.getCustomView().findViewById(R.id.txtContent).text = content + return dialog + } + + companion object { + + fun newInstance(context: Context): UiDialog { + return UiDialog(context) + } + + fun showSimpleDialog(context: Context, title: String, message: String) { + newInstance(context).materialDialog.title(text = title).message(text = message).show() + + } + } + } + + // public static class UiSweetDialog { + // + // Context mContext; + // SweetAlertDialog mSweetAlertDialog; + // + // private UiSweetDialog(Context context, int alertDialogType) { + // Iconify.with(new FontAwesomeModule()); + // mContext = context; + // mSweetAlertDialog = new SweetAlertDialog(context, alertDialogType); + // } + // + // public static UiSweetDialog newInstance(Context context, int alertDialogType) { + // return new UiSweetDialog(context, alertDialogType); + // } + // + // public SweetAlertDialog getMaterialDialog() { + // try { + // if (mSweetAlertDialog == null) { + // throw new Exception("mSweetAlertDialog is null"); + // } + // } catch (Exception e) { + // e.printStackTrace(); + // } + // return mSweetAlertDialog; + // } + // + // public static void showSimpleDialog(Context context, String title, String message) { + // + // newInstance(context, SweetAlertDialog.NORMAL_TYPE).mSweetAlertDialog.setTitleText(title).setContentText(message).show(); + // + // } + // + // public SweetAlertDialog getIndeterminateDialog(String title, String content) { + // return mBuilder + // .title(title) + // .content(content) + // .progress(true, 100, false) + // .progressIndeterminateStyle(true) + // .cancelable(false) + // .icon(new IconDrawable(mContext, FontAwesomeIcons.fa_comment).actionBarSize().color(Color.GRAY)) + // .build(); + // } + // + // public SweetAlertDialog getOKDialog(String title, String content, Drawable icon) { + // return mBuilder + // .title(title) + // .content(content) + // .cancelable(false) + // .icon(icon == null ? new IconDrawable(mContext, FontAwesomeIcons.fa_angle_right).actionBarSize().color(Color.GRAY) : icon) + // .onPositive(new MaterialDialog.SingleButtonCallback() { + // @Override + // public void onClick(MaterialDialog dialog, DialogAction which) { + // dialog.dismiss(); + // } + // }) + // .positiveText("Devam Et") + // .build(); + // } + // + // public SweetAlertDialog getOKCancelDialog(final String title, String content, final String whenClickOkText, Drawable icon) { + // + // mSweetAlertDialog.setTitleText(title); + // mSweetAlertDialog.setContentText(content); + // mSweetAlertDialog.setCancelable(false); + // mSweetAlertDialog.setCustomImage(icon); + // mSweetAlertDialog.setCancelText("İptal Et"); + // mSweetAlertDialog.setConfirmText("Devam et"); + // + // mSweetAlertDialog.setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() { + // @Override + // public void onClick(SweetAlertDialog sweetAlertDialog) { + // sweetAlertDialog.dismiss(); + // } + // }); + // + // mSweetAlertDialog.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { + // @Override + // public void onClick(SweetAlertDialog sweetAlertDialog) { + // sweetAlertDialog + // .setTitleText(title) + // .setContentText(whenClickOkText) + // .showCancelButton(false) + // .setConfirmText("Tamam") + // .setConfirmClickListener(null) + // .changeAlertType(SweetAlertDialog.SUCCESS_TYPE); + // } + // }); + // + // mSweetAlertDialog.show(); + // + // return mSweetAlertDialog; + // + // + // return mBuilder + // .title(title) + // .content(content) + // .cancelable(false) + // .icon(icon == null ? new IconDrawable(mContext, FontAwesomeIcons.fa_angle_right).actionBarSize().color(Color.GRAY) : icon) + // .onPositive(new MaterialDialog.SingleButtonCallback() { + // @Override + // public void onClick(MaterialDialog dialog, DialogAction which) { + // dialog.dismiss(); + // } + // }) + // .onNegative(new MaterialDialog.SingleButtonCallback() { + // @Override + // public void onClick(MaterialDialog dialog, DialogAction which) { + // dialog.dismiss(); + // } + // }) + // .negativeText("İptal Et") + // .positiveText("Devam Et") + // .negativeColor(Color.GRAY) + // .positiveColor(mContext.getResources().getColor(R.color.accent)) + // .build(); + // } + // + // public SweetAlertDialog getProgressDialog(String title, String content, Drawable icon) { + // + // mSweetAlertDialog.setTitleText(title); + // mSweetAlertDialog.setContentText(content); + // mSweetAlertDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86")); + // mSweetAlertDialog.setCancelable(false); + // mSweetAlertDialog.show(); + // + // return mSweetAlertDialog; + // } + // + // public SweetAlertDialog getProgressDialog(String content, Drawable icon) { + // + // mSweetAlertDialog.setContentText(content); + // mSweetAlertDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86")); + // mSweetAlertDialog.setCancelable(false); + // mSweetAlertDialog.show(); + // + // return mSweetAlertDialog; + // } + // } + + class UiSnackBar private constructor(view: View, text: String?, duration: Int) { + var snackbar: Snackbar + internal set + + init { + snackbar = Snackbar.make(view, text ?: "", duration) + } + + fun setText(text: String): UiSnackBar { + snackbar.setText(text) + return this + } + + fun setDuration(duration: Int): UiSnackBar { + snackbar.duration = duration + return this + } + + fun setBackgroundColor(color: Int): UiSnackBar { + snackbar.view.setBackgroundColor(color) + return this + } + + fun setActionTextColor(color: Int): UiSnackBar { + snackbar.setActionTextColor(color) + return this + } + + fun setMessageTextColor(color: Int): UiSnackBar { + val textView = snackbar.view.findViewById(R.id.snackbar_text) as TextView + textView.setTextColor(color) + return this + } + + fun show() { + snackbar.show() + } + + companion object { + + fun newInstance(view: View, text: String, duration: Int): Snackbar { + return UiSnackBar(view, text, duration).snackbar + } + + fun newInstance(context: Context, view: View): UiSnackBar { + return UiSnackBar(view, null, Snackbar.LENGTH_LONG) + } + + fun showSimpleSnackBar(view: View?, text: String, duration: Int) { + if (view == null) return + + val snackbar = Snackbar.make(view, text, duration) + val textView = snackbar.view.findViewById(R.id.snackbar_text) + textView.setTextColor(Color.WHITE) + + snackbar.show() + } + + private fun findSuitableParent(view: View?): ViewGroup? { + var view = view + var fallback: ViewGroup? = null + do { + if (view is CoordinatorLayout) { + // We've found a CoordinatorLayout, use it + return view + } else if (view is FrameLayout) { + if (view.id == android.R.id.content) { + // If we've hit the decor content view, then we didn't find a CoL in the + // hierarchy, so use it. + return view + } else { + // It's not the content view but we'll use it as our fallback + fallback = view + } + } + + if (view != null) { + // Else, we will loop and crawl up the view hierarchy and try to find a parent + val parent = view.parent + view = if (parent is View) parent else null + } + } while (view != null) + + // If we reach here then we didn't find a CoL or a suitable content view so we'll fallback + return fallback + } + } + + } + + class UiToast private constructor(context: Context, text: String?, duration: Int) { + + var toast: Toast + + init { + toast = Toast.makeText(context, text, duration) + } + + fun setText(text: String): UiToast { + toast.setText(text) + return this + } + + fun setDuration(duration: Int): UiToast { + toast.duration = duration + return this + } + + fun setBackgroundColor(color: Int): UiToast { + toast.view.setBackgroundColor(color) + return this + } + + fun show() { + toast.show() + } + + companion object { + + fun newInstance(context: Context, text: String, duration: Int): Toast { + return UiToast(context, text, duration).toast + } + + fun newInstance(context: Context): UiToast { + return UiToast(context, null, Toast.LENGTH_LONG) + } + + fun showSimpleToast(context: Context, text: String, duration: Int) { + Toast.makeText(context, text, duration).show() + + } + } + } +} diff --git a/androidbasichelperlib/src/main/res/layout/progress_dialog_horizontal_layout.xml b/androidbasichelperlib/src/main/res/layout/progress_dialog_horizontal_layout.xml new file mode 100644 index 0000000..fc45aaa --- /dev/null +++ b/androidbasichelperlib/src/main/res/layout/progress_dialog_horizontal_layout.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/androidbasichelperlib/src/main/res/layout/progress_dialog_layout.xml b/androidbasichelperlib/src/main/res/layout/progress_dialog_layout.xml new file mode 100644 index 0000000..bd988d5 --- /dev/null +++ b/androidbasichelperlib/src/main/res/layout/progress_dialog_layout.xml @@ -0,0 +1,26 @@ + + + + + + + + \ No newline at end of file diff --git a/androidbasichelperlib/src/main/res/values/styles.xml b/androidbasichelperlib/src/main/res/values/styles.xml index 2a08876..9718aec 100644 --- a/androidbasichelperlib/src/main/res/values/styles.xml +++ b/androidbasichelperlib/src/main/res/values/styles.xml @@ -12,4 +12,8 @@ + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 0941836..cbd47b6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,5 +25,5 @@ dependencies { testImplementation 'junit:junit:4.12' implementation("androidx.appcompat:appcompat:1.0.0") implementation project(':androidbasichelperlib') - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" } diff --git a/app/src/main/java/com/aykuttasil/androidbasichelper/MainActivity.kt b/app/src/main/java/com/aykuttasil/androidbasichelper/MainActivity.kt index 64bd7b4..d1357df 100644 --- a/app/src/main/java/com/aykuttasil/androidbasichelper/MainActivity.kt +++ b/app/src/main/java/com/aykuttasil/androidbasichelper/MainActivity.kt @@ -3,13 +3,20 @@ package com.aykuttasil.androidbasichelper import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import com.aykuttasil.androidbasichelperlib.UiHelper +import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) + setTheme(R.style.AppTheme_MyX) - UiHelper.UiDialog.newInstance(this).getOKDialog("","",null) + btnShowDialog.setOnClickListener { + //UiHelper.UiDialog.newInstance(this).getOKDialog("title", "content", null).debugMode(false).show() + //UiHelper.UiDialog.newInstance(this).getProgressDialog("Reaktif", "İşlem Yapılıyor.\nLütfen Bekleyin...", null).debugMode(false).show() + UiHelper.UiDialog.newInstance(this).getIndeterminateDialog("Reaktif").show() + + } } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 2901aeb..5012313 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -3,14 +3,15 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" - android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.aykuttasil.androidbasichelper.MainActivity"> - + android:text="Show Dialog" /> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5885930..606690f 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,11 +1,13 @@ - - + diff --git a/build.gradle b/build.gradle index 26a31fd..af21742 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.3.1' + classpath 'com.android.tools.build:gradle:3.3.2' //classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' //classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"