diff --git a/agendacalendarview/.gitignore b/agendacalendarview/.gitignore deleted file mode 100644 index 796b96d1..00000000 --- a/agendacalendarview/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/agendacalendarview/build.gradle b/agendacalendarview/build.gradle deleted file mode 100644 index 92731fb9..00000000 --- a/agendacalendarview/build.gradle +++ /dev/null @@ -1,54 +0,0 @@ -apply plugin: 'com.android.library' -//apply plugin: 'me.tatarka.retrolambda' - -android { - compileSdkVersion setup.compileSdk - - android { - lintOptions { - abortOnError false - } - } - - defaultConfig { - minSdkVersion 14 - targetSdkVersion setup.targetSdk - versionCode 1 - versionName "1.0" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - debugMinify { - debuggable = true - minifyEnabled = true - proguardFiles 'proguard-android.txt' - } - } - sourceSets { - main { - assets.srcDirs = ['assets'] - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -} - -//apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle' - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - // Google libraries - implementation "androidx.appcompat:appcompat:${versions.appcompat}" - implementation "androidx.recyclerview:recyclerview:${versions.recyclerView}" - implementation "com.google.android.material:material:${versions.material}" - - // other libraries - //implementation 'se.emilsjolander:stickylistheaders:2.7.0' - implementation 'com.github.edisonw:StickyListHeaders:master-SNAPSHOT@aar' - implementation 'io.reactivex:rxjava:1.1.1' -} diff --git a/agendacalendarview/src/main/AndroidManifest.xml b/agendacalendarview/src/main/AndroidManifest.xml deleted file mode 100644 index 38e54711..00000000 --- a/agendacalendarview/src/main/AndroidManifest.xml +++ /dev/null @@ -1,3 +0,0 @@ - - diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/AgendaCalendarView.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/AgendaCalendarView.java deleted file mode 100644 index 0d0c0cf4..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/AgendaCalendarView.java +++ /dev/null @@ -1,264 +0,0 @@ -package com.github.tibolte.agendacalendarview; - -import android.animation.Animator; -import android.animation.ObjectAnimator; -import android.content.Context; -import android.content.res.ColorStateList; -import android.content.res.TypedArray; -import android.os.Handler; -import androidx.annotation.NonNull; -import android.util.AttributeSet; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.AbsListView; -import android.widget.AdapterView; -import android.widget.FrameLayout; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.github.tibolte.agendacalendarview.agenda.AgendaAdapter; -import com.github.tibolte.agendacalendarview.agenda.AgendaView; -import com.github.tibolte.agendacalendarview.calendar.CalendarView; -import com.github.tibolte.agendacalendarview.models.BaseCalendarEvent; -import com.github.tibolte.agendacalendarview.models.CalendarEvent; -import com.github.tibolte.agendacalendarview.models.DayItem; -import com.github.tibolte.agendacalendarview.models.IDayItem; -import com.github.tibolte.agendacalendarview.models.IWeekItem; -import com.github.tibolte.agendacalendarview.models.WeekItem; -import com.github.tibolte.agendacalendarview.render.DefaultEventRenderer; -import com.github.tibolte.agendacalendarview.render.EventRenderer; -import com.github.tibolte.agendacalendarview.utils.BusProvider; -import com.github.tibolte.agendacalendarview.utils.Events; -import com.github.tibolte.agendacalendarview.utils.ListViewScrollTracker; -import com.github.tibolte.agendacalendarview.widgets.FloatingActionButton; - -import java.util.Calendar; -import java.util.List; -import java.util.Locale; - -import se.emilsjolander.stickylistheaders.StickyListHeadersListView; - -/** - * View holding the agenda and calendar view together. - */ -public class AgendaCalendarView extends FrameLayout implements StickyListHeadersListView.OnStickyHeaderChangedListener { - - private static final String LOG_TAG = AgendaCalendarView.class.getSimpleName(); - - private CalendarView mCalendarView; - private AgendaView mAgendaView; - private FloatingActionButton mFloatingActionButton; - - private int mAgendaCurrentDayTextColor, mCalendarHeaderColor, mCalendarHeaderTextColor, mCalendarBackgroundColor, mCalendarDayTextColor, mCalendarPastDayTextColor, mCalendarCurrentDayColor, mFabColor; - private CalendarPickerController mCalendarPickerController; - - public AgendaView getAgendaView() { - return mAgendaView; - } - - private ListViewScrollTracker mAgendaListViewScrollTracker; - private AbsListView.OnScrollListener mAgendaScrollListener = new AbsListView.OnScrollListener() { - int mCurrentAngle; - int mMaxAngle = 85; - - @Override - public void onScrollStateChanged(AbsListView view, int scrollState) { - - } - - @Override - public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { - int scrollY = mAgendaListViewScrollTracker.calculateScrollY(firstVisibleItem, visibleItemCount); - if (scrollY != 0) { - mFloatingActionButton.show(); - } - //Log.d(LOG_TAG, String.format("Agenda listView scrollY: %d", scrollY)); - /*int toAngle = scrollY / 100; - if (toAngle > mMaxAngle) { - toAngle = mMaxAngle; - } else if (toAngle < -mMaxAngle) { - toAngle = -mMaxAngle; - } - RotateAnimation rotate = new RotateAnimation(mCurrentAngle, toAngle, mFloatingActionButton.getWidth() / 2, mFloatingActionButton.getHeight() / 2); - rotate.setFillAfter(true); - mCurrentAngle = toAngle; - mFloatingActionButton.startAnimation(rotate);*/ - } - }; - - // region Constructors - - public AgendaCalendarView(Context context) { - super(context); - } - - public AgendaCalendarView(Context context, AttributeSet attrs) { - super(context, attrs); - - TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ColorOptionsView, 0, 0); - mAgendaCurrentDayTextColor = a.getColor(R.styleable.ColorOptionsView_agendaCurrentDayTextColor, getResources().getColor(R.color.theme_primary)); - mCalendarHeaderColor = a.getColor(R.styleable.ColorOptionsView_calendarHeaderColor, getResources().getColor(R.color.theme_primary_dark)); - mCalendarHeaderTextColor = a.getColor(R.styleable.ColorOptionsView_calendarHeaderTextColor, getResources().getColor(R.color.theme_text_icons)); - mCalendarBackgroundColor = a.getColor(R.styleable.ColorOptionsView_calendarColor, getResources().getColor(R.color.theme_primary)); - mCalendarDayTextColor = a.getColor(R.styleable.ColorOptionsView_calendarDayTextColor, getResources().getColor(R.color.theme_text_icons)); - mCalendarCurrentDayColor = a.getColor(R.styleable.ColorOptionsView_calendarCurrentDayTextColor, getResources().getColor(R.color.calendar_text_current_day)); - mCalendarPastDayTextColor = a.getColor(R.styleable.ColorOptionsView_calendarPastDayTextColor, getResources().getColor(R.color.theme_light_primary)); - mFabColor = a.getColor(R.styleable.ColorOptionsView_fabColor, getResources().getColor(R.color.theme_accent)); - - LayoutInflater inflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - inflater.inflate(R.layout.view_agendacalendar, this, true); - - setAlpha(0f); - } - - // endregion - - // region Class - View - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - mCalendarView = (CalendarView) findViewById(R.id.calendar_view); - mAgendaView = (AgendaView) findViewById(R.id.agenda_view); - mFloatingActionButton = (FloatingActionButton) findViewById(R.id.floating_action_button); - ColorStateList csl = new ColorStateList(new int[][]{new int[0]}, new int[]{mFabColor}); - mFloatingActionButton.setBackgroundTintList(csl); - - LinearLayout mDayNamesHeader = mCalendarView.findViewById(R.id.cal_day_names); - mDayNamesHeader.setBackgroundColor(mCalendarHeaderColor); - for (int i = 0; i < mDayNamesHeader.getChildCount(); i++) { - TextView txtDay = (TextView) mDayNamesHeader.getChildAt(i); - txtDay.setTextColor(mCalendarHeaderTextColor); - } - mCalendarView.findViewById(R.id.list_week).setBackgroundColor(mCalendarBackgroundColor); - - mAgendaView.getAgendaListView().setOnItemClickListener((AdapterView parent, View view, int position, long id) -> { - mCalendarPickerController.onEventSelected(CalendarManager.getInstance().getEvents().get(position)); - }); - - BusProvider.getInstance().toObserverable() - .subscribe(event -> { - if (event instanceof Events.DayClickedEvent) { - if (mCalendarPickerController != null) - mCalendarPickerController.onDaySelected(((Events.DayClickedEvent) event).getDay()); - } else if (event instanceof Events.EventsFetched) { - ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(this, "alpha", getAlpha(), 1f).setDuration(500); - alphaAnimation.addListener(new Animator.AnimatorListener() { - @Override - public void onAnimationStart(Animator animation) { - - } - - @Override - public void onAnimationEnd(Animator animation) { - long fabAnimationDelay = 500; - // Just after setting the alpha from this view to 1, we hide the fab. - // It will reappear as soon as the user is scrolling the Agenda view. - new Handler().postDelayed(() -> { - mFloatingActionButton.hide(); - mAgendaListViewScrollTracker = new ListViewScrollTracker(mAgendaView.getAgendaListView()); - mAgendaView.getAgendaListView().setOnScrollListener(mAgendaScrollListener); - mFloatingActionButton.setOnClickListener((v) -> { - mAgendaView.translateList(0); - mAgendaView.getAgendaListView().smoothScrollBy(0, 0); - //mAgendaView.getAgendaListView().getWrappedList().smoothScrollBy(0, 0); - mAgendaView.getAgendaListView().scrollToCurrentDate(CalendarManager.getInstance().getToday()); - new Handler().postDelayed(() -> mFloatingActionButton.hide(), fabAnimationDelay); - }); - }, fabAnimationDelay); - } - - @Override - public void onAnimationCancel(Animator animation) { - - } - - @Override - public void onAnimationRepeat(Animator animation) { - - } - }); - alphaAnimation.start(); - } - }); - } - - // endregion - - // region Interface - StickyListHeadersListView.OnStickyHeaderChangedListener - - @Override - public void onStickyHeaderChanged(StickyListHeadersListView stickyListHeadersListView, View header, int position, long headerId) { - //Log.d(LOG_TAG, String.format("onStickyHeaderChanged, position = %d, headerId = %d", position, headerId)); - - if (CalendarManager.getInstance().getEvents().size() > 0) { - CalendarEvent event = CalendarManager.getInstance().getEvents().get(position); - if (event != null) { - mCalendarView.scrollToDate(event); - mCalendarPickerController.onScrollToDate(event.getInstanceDay()); - } - } - } - - // endregion - - // region Public methods - - public void init(List eventList, Calendar minDate, Calendar maxDate, Locale locale, CalendarPickerController calendarPickerController, EventRenderer ... renderers) { - mCalendarPickerController = calendarPickerController; - - CalendarManager.getInstance(getContext()).buildCal(minDate, maxDate, locale, new DayItem(), new WeekItem()); - - // Feed our views with weeks list and events - mCalendarView.init(CalendarManager.getInstance(getContext()), mCalendarDayTextColor, mCalendarCurrentDayColor, mCalendarPastDayTextColor, eventList); - - // Load agenda events and scroll to current day - AgendaAdapter agendaAdapter = new AgendaAdapter(mAgendaCurrentDayTextColor); - mAgendaView.getAgendaListView().setAdapter(agendaAdapter); - mAgendaView.getAgendaListView().setOnStickyHeaderChangedListener(this); - - CalendarManager.getInstance().loadEvents(eventList, new BaseCalendarEvent()); - BusProvider.getInstance().send(new Events.EventsFetched()); - Log.d(LOG_TAG, "CalendarEventTask finished, event count "+eventList.size()); - - // add default event renderer - addEventRenderer(new DefaultEventRenderer()); - for (EventRenderer renderer: renderers) { - addEventRenderer(renderer); - } - } - - public void init(Locale locale, List lWeeks, List lDays, List lEvents, CalendarPickerController calendarPickerController) { - mCalendarPickerController = calendarPickerController; - - CalendarManager.getInstance(getContext()).loadCal(locale, lWeeks, lDays, lEvents); - - // Feed our views with weeks list and events - mCalendarView.init(CalendarManager.getInstance(getContext()), mCalendarDayTextColor, mCalendarCurrentDayColor, mCalendarPastDayTextColor, lEvents); - - // Load agenda events and scroll to current day - AgendaAdapter agendaAdapter = new AgendaAdapter(mAgendaCurrentDayTextColor); - mAgendaView.getAgendaListView().setAdapter(agendaAdapter); - mAgendaView.getAgendaListView().setOnStickyHeaderChangedListener(this); - - // notify that actually everything is loaded - BusProvider.getInstance().send(new Events.EventsFetched()); - Log.d(LOG_TAG, "CalendarEventTask finished"); - - // add default event renderer - addEventRenderer(new DefaultEventRenderer()); - } - - public void addEventRenderer(@NonNull final EventRenderer renderer) { - AgendaAdapter adapter = (AgendaAdapter) mAgendaView.getAgendaListView().getAdapter(); - adapter.addEventRenderer(renderer); - } - - public void enableFloatingIndicator(boolean enable) { - mFloatingActionButton.setVisibility(enable ? VISIBLE : GONE); - } - - // endregion -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/CalendarManager.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/CalendarManager.java deleted file mode 100644 index c661d32b..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/CalendarManager.java +++ /dev/null @@ -1,267 +0,0 @@ -package com.github.tibolte.agendacalendarview; - -import com.github.tibolte.agendacalendarview.models.CalendarEvent; -import com.github.tibolte.agendacalendarview.models.IDayItem; -import com.github.tibolte.agendacalendarview.models.IWeekItem; -import com.github.tibolte.agendacalendarview.utils.DateHelper; - -import android.content.Context; -import android.util.Log; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -/** - * This class manages information about the calendar. (Events, weather info...) - * Holds reference to the days list of the calendar. - * As the app is using several views, we want to keep everything in one place. - */ -public class CalendarManager { - - private static final String LOG_TAG = CalendarManager.class.getSimpleName(); - - private static CalendarManager mInstance; - - private Context mContext; - private Locale mLocale; - private Calendar mToday = Calendar.getInstance(); - private SimpleDateFormat mWeekdayFormatter; - private SimpleDateFormat mMonthHalfNameFormat; - - /// instances of classes provided from outside - private IDayItem mCleanDay; - private IWeekItem mCleanWeek; - - /** - * List of days used by the calendar - */ - private List mDays = new ArrayList<>(); - /** - * List of weeks used by the calendar - */ - private List mWeeks = new ArrayList<>(); - /** - * List of events instances - */ - private List mEvents = new ArrayList<>(); - - // region Constructors - - public CalendarManager(Context context) { - this.mContext = context; - } - - public static CalendarManager getInstance(Context context) { - if (mInstance == null) { - mInstance = new CalendarManager(context); - } - return mInstance; - } - - public static CalendarManager getInstance() { - return mInstance; - } - - // endregion - - // region Getters/Setters - - public Locale getLocale() { - return mLocale; - } - - public Context getContext() { - return mContext; - } - - public Calendar getToday() { - return mToday; - } - - public void setToday(Calendar today) { - this.mToday = today; - } - - public List getWeeks() { - return mWeeks; - } - - public List getEvents() { - return mEvents; - } - - public List getDays() { - return mDays; - } - - public SimpleDateFormat getWeekdayFormatter() { - return mWeekdayFormatter; - } - - public SimpleDateFormat getMonthHalfNameFormat() { - return mMonthHalfNameFormat; - } - - // endregion - - // region Public methods - - public void buildCal(Calendar minDate, Calendar maxDate, Locale locale, IDayItem cleanDay, IWeekItem cleanWeek) { - if (minDate == null || maxDate == null) { - throw new IllegalArgumentException( - "minDate and maxDate must be non-null."); - } - if (minDate.after(maxDate)) { - throw new IllegalArgumentException( - "minDate must be before maxDate."); - } - if (locale == null) { - throw new IllegalArgumentException("Locale is null."); - } - - setLocale(locale); - - mDays.clear(); - mWeeks.clear(); - mEvents.clear(); - - mCleanDay = cleanDay; - mCleanWeek = cleanWeek; - - Calendar mMinCal = Calendar.getInstance(mLocale); - Calendar mMaxCal = Calendar.getInstance(mLocale); - Calendar mWeekCounter = Calendar.getInstance(mLocale); - - mMinCal.setTime(minDate.getTime()); - mMaxCal.setTime(maxDate.getTime()); - - // maxDate is exclusive, here we bump back to the previous day, as maxDate if December 1st, 2020, - // we don't include that month in our list - mMaxCal.add(Calendar.MINUTE, -1); - - // Now iterate we iterate between mMinCal and mMaxCal so we build our list of weeks - mWeekCounter.setTime(mMinCal.getTime()); - int maxMonth = mMaxCal.get(Calendar.MONTH); - int maxYear = mMaxCal.get(Calendar.YEAR); - - int currentMonth = mWeekCounter.get(Calendar.MONTH); - int currentYear = mWeekCounter.get(Calendar.YEAR); - - // Loop through the weeks - while ((currentMonth <= maxMonth // Up to, including the month. - || currentYear < maxYear) // Up to the year. - && currentYear < maxYear + 1) { // But not > next yr. - - Date date = mWeekCounter.getTime(); - // Build our week list - int currentWeekOfYear = mWeekCounter.get(Calendar.WEEK_OF_YEAR); - - IWeekItem weekItem = cleanWeek.copy(); - weekItem.setWeekInYear(currentWeekOfYear); - weekItem.setYear(currentYear); - weekItem.setDate(date); - weekItem.setMonth(currentMonth); - weekItem.setLabel(mMonthHalfNameFormat.format(date)); - List dayItems = getDayCells(mWeekCounter); // gather days for the built week - weekItem.setDayItems(dayItems); - mWeeks.add(weekItem); - - //Log.d(LOG_TAG, String.format("Adding week: %s", weekItem)); - - mWeekCounter.add(Calendar.WEEK_OF_YEAR, 1); - - currentMonth = mWeekCounter.get(Calendar.MONTH); - currentYear = mWeekCounter.get(Calendar.YEAR); - } - } - - public void loadEvents(List eventList, CalendarEvent noEvent) { - - for (IWeekItem weekItem : getWeeks()) { - for (IDayItem dayItem : weekItem.getDayItems()) { - boolean isEventForDay = false; - boolean isShowBadgeForDay = false; - for (CalendarEvent event : eventList) { - if (DateHelper.isBetweenInclusive(dayItem.getDate(), event.getStartTime(), event.getEndTime())) { - CalendarEvent copy = event.copy(); - - if (copy.getShowBadge()) { - isShowBadgeForDay = true; - } - - Calendar dayInstance = Calendar.getInstance(); - dayInstance.setTime(dayItem.getDate()); - copy.setInstanceDay(dayInstance); - copy.setDayReference(dayItem); - copy.setWeekReference(weekItem); - // add instances in chronological order - getEvents().add(copy); - isEventForDay = true; - } - } - if (!isEventForDay) { - Calendar dayInstance = Calendar.getInstance(); - dayInstance.setTime(dayItem.getDate()); - CalendarEvent copy = noEvent.copy(); - - copy.setInstanceDay(dayInstance); - copy.setDayReference(dayItem); - copy.setWeekReference(weekItem); - copy.setLocation(""); - copy.setTitle(getContext().getResources().getString(R.string.agenda_event_no_events)); - copy.setPlaceholder(true); - getEvents().add(copy); - } - dayItem.setShowBadge(isShowBadgeForDay); - } - } - } - - public void loadCal (Locale locale, List lWeeks, List lDays, List lEvents) { - mWeeks = lWeeks; - mDays = lDays; - mEvents = lEvents; - setLocale(locale); - } - - // endregion - - // region Private methods - - private List getDayCells(Calendar startCal) { - Calendar cal = Calendar.getInstance(mLocale); - cal.setTime(startCal.getTime()); - List dayItems = new ArrayList<>(); - - int firstDayOfWeek = cal.get(Calendar.DAY_OF_WEEK); - int offset = cal.getFirstDayOfWeek() - firstDayOfWeek; - if (offset > 0) { - offset -= 7; - } - cal.add(Calendar.DATE, offset); - - //Log.d(LOG_TAG, String.format("Buiding row week starting at %s", cal.getTime())); - for (int c = 0; c < 7; c++) { - IDayItem dayItem = mCleanDay.copy(); - dayItem.buildDayItemFromCal(cal); - dayItems.add(dayItem); - cal.add(Calendar.DATE, 1); - } - - mDays.addAll(dayItems); - return dayItems; - } - - private void setLocale(Locale locale) { - this.mLocale = locale; - setToday(Calendar.getInstance(mLocale)); - mWeekdayFormatter = new SimpleDateFormat(getContext().getString(R.string.day_name_format), mLocale); - mMonthHalfNameFormat = new SimpleDateFormat(getContext().getString(R.string.month_half_name_format), locale); - } - - // endregion -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/CalendarPickerController.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/CalendarPickerController.java deleted file mode 100644 index a2a86dde..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/CalendarPickerController.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.tibolte.agendacalendarview; - -import com.github.tibolte.agendacalendarview.models.CalendarEvent; -import com.github.tibolte.agendacalendarview.models.IDayItem; - -import java.util.Calendar; - -public interface CalendarPickerController { - void onDaySelected(IDayItem dayItem); - - void onEventSelected(CalendarEvent event); - - void onScrollToDate(Calendar calendar); -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/agenda/AgendaAdapter.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/agenda/AgendaAdapter.java deleted file mode 100644 index 2e6c6d31..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/agenda/AgendaAdapter.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.github.tibolte.agendacalendarview.agenda; - -import com.github.tibolte.agendacalendarview.models.CalendarEvent; -import com.github.tibolte.agendacalendarview.render.DefaultEventRenderer; -import com.github.tibolte.agendacalendarview.render.EventRenderer; - -import androidx.annotation.NonNull; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; - -import java.util.ArrayList; -import java.util.List; - -import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter; - -/** - * Adapter for the agenda, implements StickyListHeadersAdapter. - * Days as sections and CalendarEvents as list items. - */ -public class AgendaAdapter extends BaseAdapter implements StickyListHeadersAdapter { - - private List mEvents = new ArrayList<>(); - private List> mRenderers = new ArrayList<>(); - private int mCurrentDayColor; - - // region Constructor - - public AgendaAdapter(int currentDayTextColor) { - this.mCurrentDayColor = currentDayTextColor; - } - - // endregion - - // region Public methods - - public void updateEvents(List events) { - this.mEvents.clear(); - this.mEvents.addAll(events); - notifyDataSetChanged(); - } - - // endregion - - // region Interface - StickyListHeadersAdapter - - @Override - public View getHeaderView(int position, View convertView, ViewGroup parent) { - AgendaHeaderView agendaHeaderView = (AgendaHeaderView) convertView; - if (agendaHeaderView == null) { - agendaHeaderView = AgendaHeaderView.inflate(parent); - } - agendaHeaderView.setDay(getItem(position).getInstanceDay(), mCurrentDayColor, getItem(position).getDayReference().getShowBadge()); - return agendaHeaderView; - } - - @Override - public long getHeaderId(int position) { - return mEvents.get(position).getInstanceDay().getTimeInMillis(); - } - - // endregion - - // region Class - BaseAdapter - - @Override - public int getCount() { - return mEvents.size(); - } - - @Override - public CalendarEvent getItem(int position) { - return mEvents.get(position); - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - EventRenderer eventRenderer = new DefaultEventRenderer(); - final CalendarEvent event = getItem(position); - - // Search for the correct event renderer - for (EventRenderer renderer : mRenderers) { - if(event.getClass().isAssignableFrom(renderer.getRenderType())) { - eventRenderer = renderer; - break; - } - } - convertView = LayoutInflater.from(parent.getContext()) - .inflate(eventRenderer.getEventLayout(), parent, false); - eventRenderer.render(convertView, event); - return convertView; - } - - public void addEventRenderer(@NonNull final EventRenderer renderer) { - mRenderers.add(renderer); - } - - // endregion -} \ No newline at end of file diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/agenda/AgendaEventView.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/agenda/AgendaEventView.java deleted file mode 100644 index 198f65cd..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/agenda/AgendaEventView.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.tibolte.agendacalendarview.agenda; - -import com.github.tibolte.agendacalendarview.R; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.ViewGroup; -import android.widget.LinearLayout; - -/** - * List item view for the StickyHeaderListView of the agenda view - */ -public class AgendaEventView extends LinearLayout { - public static AgendaEventView inflate(ViewGroup parent) { - return (AgendaEventView) LayoutInflater.from(parent.getContext()).inflate(R.layout.view_agenda_event, parent, false); - } - - // region Constructors - - public AgendaEventView(Context context) { - this(context, null); - } - - public AgendaEventView(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public AgendaEventView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - setPadding(getResources().getDimensionPixelSize(R.dimen.agenda_event_view_padding_left), - getResources().getDimensionPixelSize(R.dimen.agenda_event_view_padding_top), - getResources().getDimensionPixelSize(R.dimen.agenda_event_view_padding_right), - getResources().getDimensionPixelSize(R.dimen.agenda_event_view_padding_bottom)); - } - - // endregion -} \ No newline at end of file diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/agenda/AgendaHeaderView.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/agenda/AgendaHeaderView.java deleted file mode 100644 index 36b16ddb..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/agenda/AgendaHeaderView.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.github.tibolte.agendacalendarview.agenda; - -import com.github.tibolte.agendacalendarview.CalendarManager; -import com.github.tibolte.agendacalendarview.R; -import com.github.tibolte.agendacalendarview.utils.DateHelper; - -import android.content.Context; -import android.content.res.Resources; -import android.graphics.drawable.GradientDrawable; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.LinearLayout; -import android.widget.TextView; - -import java.text.SimpleDateFormat; -import java.util.Calendar; - -/** - * Header view for the StickyHeaderListView of the agenda view - */ -public class AgendaHeaderView extends LinearLayout { - - public static AgendaHeaderView inflate(ViewGroup parent) { - return (AgendaHeaderView) LayoutInflater.from(parent.getContext()).inflate(R.layout.view_agenda_header, parent, false); - } - - // region Constructors - - public AgendaHeaderView(Context context) { - super(context); - } - - public AgendaHeaderView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public AgendaHeaderView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - // endregion - - // region Public methods - - public void setDay(Calendar day, int currentDayTextColor, boolean showBadge) { - TextView txtDayOfMonth = (TextView) findViewById(R.id.view_agenda_day_of_month); - TextView txtDayOfWeek = (TextView) findViewById(R.id.view_agenda_day_of_week); - TextView txtDay = (TextView) findViewById(R.id.view_agenda_day_text); - View circleView = findViewById(R.id.view_day_circle_selected); - - Calendar today = CalendarManager.getInstance().getToday(); - - SimpleDateFormat dayWeekFormatter = new SimpleDateFormat(getContext().getString(R.string.day_name_format), CalendarManager.getInstance().getLocale()); - SimpleDateFormat dayWeekLongFormatter = new SimpleDateFormat("EEEE", CalendarManager.getInstance().getLocale()); - - txtDayOfMonth.setTextColor(getResources().getColor(R.color.calendar_text_default)); - txtDayOfWeek.setTextColor(getResources().getColor(R.color.calendar_text_default)); - - if (DateHelper.sameDate(day, today)) { - txtDayOfMonth.setTextColor(currentDayTextColor); - circleView.setVisibility(VISIBLE); - GradientDrawable drawable = (GradientDrawable) circleView.getBackground(); - drawable.setStroke((int) (2 * Resources.getSystem().getDisplayMetrics().density), currentDayTextColor); - } else if (showBadge) { - circleView.setVisibility(VISIBLE); - GradientDrawable drawable = (GradientDrawable) circleView.getBackground(); - drawable.setStroke((int) (2 * Resources.getSystem().getDisplayMetrics().density), 0xffff0000); - } - else { - circleView.setVisibility(INVISIBLE); - } - - txtDayOfMonth.setText(String.valueOf(day.get(Calendar.DAY_OF_MONTH))); - txtDayOfWeek.setText(dayWeekFormatter.format(day.getTime())); - //txtDay.setText(dayWeekLongFormatter.format(day.getTime())); - } - - // endregion -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/agenda/AgendaListView.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/agenda/AgendaListView.java deleted file mode 100644 index 235b04c6..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/agenda/AgendaListView.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.github.tibolte.agendacalendarview.agenda; - -import com.github.tibolte.agendacalendarview.CalendarManager; -import com.github.tibolte.agendacalendarview.models.CalendarEvent; -import com.github.tibolte.agendacalendarview.utils.DateHelper; - -import android.content.Context; -import android.util.AttributeSet; - -import java.util.Calendar; -import java.util.List; - -import se.emilsjolander.stickylistheaders.StickyListHeadersListView; - -/** - * StickyListHeadersListView to scroll chronologically through events. - */ -public class AgendaListView extends StickyListHeadersListView { - - // region Constructors - - public AgendaListView(Context context) { - super(context); - } - - public AgendaListView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public AgendaListView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - // endregion - - // region Public methods - - public void scrollToCurrentDate(Calendar today) { - List events = CalendarManager.getInstance().getEvents(); - - int toIndex = 0; - for (int i = 0; i < events.size(); i++) { - if (DateHelper.sameDate(today, events.get(i).getInstanceDay())) { - toIndex = i; - break; - } - } - - final int finalToIndex = toIndex; - post(()->setSelection(finalToIndex)); - } - - // endregion -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/agenda/AgendaView.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/agenda/AgendaView.java deleted file mode 100644 index 80b317da..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/agenda/AgendaView.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.github.tibolte.agendacalendarview.agenda; - -import android.animation.Animator; -import android.animation.ObjectAnimator; -import android.content.Context; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewTreeObserver; -import android.widget.FrameLayout; - -import com.github.tibolte.agendacalendarview.CalendarManager; -import com.github.tibolte.agendacalendarview.R; -import com.github.tibolte.agendacalendarview.utils.BusProvider; -import com.github.tibolte.agendacalendarview.utils.Events; - -public class AgendaView extends FrameLayout { - - private AgendaListView mAgendaListView; - private View mShadowView; - - // region Constructors - - public AgendaView(Context context) { - super(context); - } - - public AgendaView(Context context, AttributeSet attrs) { - super(context, attrs); - - LayoutInflater inflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - inflater.inflate(R.layout.view_agenda, this, true); - } - - // endregion - - // region Class - View - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - - mAgendaListView = (AgendaListView) findViewById(R.id.agenda_listview); - mShadowView = findViewById(R.id.view_shadow); - - BusProvider.getInstance().toObserverable() - .subscribe(event -> { - if (event instanceof Events.DayClickedEvent) { - Events.DayClickedEvent clickedEvent = (Events.DayClickedEvent) event; - getAgendaListView().scrollToCurrentDate(clickedEvent.getCalendar()); - } else if (event instanceof Events.CalendarScrolledEvent) { - int offset = (int) (3 * getResources().getDimension(R.dimen.day_cell_height)); - translateList(offset); - } else if (event instanceof Events.EventsFetched) { - if (getAgendaListView().getAdapter() != null) - ((AgendaAdapter) getAgendaListView().getAdapter()).updateEvents(CalendarManager.getInstance().getEvents()); - - getViewTreeObserver().addOnGlobalLayoutListener( - new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - if (getWidth() != 0 && getHeight() != 0) { - // display only two visible rows on the calendar view - ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) getLayoutParams(); - int height = getHeight(); - int margin = (int) (getContext().getResources().getDimension(R.dimen.calendar_header_height) + 2 * getContext().getResources().getDimension(R.dimen.day_cell_height)); - layoutParams.height = height; - layoutParams.setMargins(0, margin, 0, 0); - setLayoutParams(layoutParams); - - getAgendaListView().scrollToCurrentDate(CalendarManager.getInstance().getToday()); - - getViewTreeObserver().removeGlobalOnLayoutListener(this); - } - } - } - - ); - } else if (event instanceof Events.ForecastFetched) { - ((AgendaAdapter) getAgendaListView().getAdapter()).updateEvents(CalendarManager.getInstance().getEvents()); - } - }); - } - - @Override - public boolean dispatchTouchEvent(MotionEvent event) { - int eventaction = event.getAction(); - - switch (eventaction) { - case MotionEvent.ACTION_DOWN: - // if the user touches the listView, we put it back to the top - translateList(0); - break; - default: - break; - } - - return super.dispatchTouchEvent(event); - } - - // endregion - - // region Public methods - - public AgendaListView getAgendaListView() { - return mAgendaListView; - } - - public void translateList(int targetY) { - if (targetY != getTranslationY()) { - ObjectAnimator mover = ObjectAnimator.ofFloat(this, "translationY", targetY); - mover.setDuration(150); - mover.addListener(new Animator.AnimatorListener() { - @Override - public void onAnimationStart(Animator animation) { - //mShadowView.setVisibility(GONE); - } - - @Override - public void onAnimationEnd(Animator animation) { - if (targetY == 0) { - BusProvider.getInstance().send(new Events.AgendaListViewTouchedEvent()); - } - //mShadowView.setVisibility(VISIBLE); - } - - @Override - public void onAnimationCancel(Animator animation) { - - } - - @Override - public void onAnimationRepeat(Animator animation) { - - } - }); - mover.start(); - } - } - - // endregion -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/calendar/CalendarView.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/calendar/CalendarView.java deleted file mode 100644 index 67d7490c..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/calendar/CalendarView.java +++ /dev/null @@ -1,279 +0,0 @@ -package com.github.tibolte.agendacalendarview.calendar; - -import com.github.tibolte.agendacalendarview.CalendarManager; -import com.github.tibolte.agendacalendarview.R; -import com.github.tibolte.agendacalendarview.calendar.weekslist.WeekListView; -import com.github.tibolte.agendacalendarview.calendar.weekslist.WeeksAdapter; -import com.github.tibolte.agendacalendarview.models.CalendarEvent; -import com.github.tibolte.agendacalendarview.models.IDayItem; -import com.github.tibolte.agendacalendarview.models.IWeekItem; -import com.github.tibolte.agendacalendarview.utils.BusProvider; -import com.github.tibolte.agendacalendarview.utils.DateHelper; -import com.github.tibolte.agendacalendarview.utils.Events; - -import android.content.Context; -import androidx.recyclerview.widget.LinearLayoutManager; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.ViewGroup; -import android.view.ViewTreeObserver; -import android.widget.LinearLayout; -import android.widget.TextView; - -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.List; -import java.util.Locale; - -/** - * The calendar view is a freely scrolling view that allows the user to browse between days of the - * year. - */ -public class CalendarView extends LinearLayout { - - private static final String LOG_TAG = CalendarView.class.getSimpleName(); - - /** - * Top of the calendar view layout, the week days list - */ - private LinearLayout mDayNamesHeader; - /** - * Part of the calendar view layout always visible, the weeks list - */ - private WeekListView mListViewWeeks; - /** - * The adapter for the weeks list - */ - private WeeksAdapter mWeeksAdapter; - /** - * The current highlighted day in blue - */ - private IDayItem mSelectedDay; - /** - * The current row displayed at top of the list - */ - private int mCurrentListPosition; - - // region Constructors - - public CalendarView(Context context) { - super(context); - } - - public CalendarView(Context context, AttributeSet attrs) { - super(context, attrs); - - LayoutInflater inflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - inflater.inflate(R.layout.view_calendar, this, true); - - setOrientation(VERTICAL); - } - - // endregion - - public IDayItem getSelectedDay() { - return mSelectedDay; - } - - public void setSelectedDay(IDayItem mSelectedDay) { - this.mSelectedDay = mSelectedDay; - } - - public WeekListView getListViewWeeks() { - return mListViewWeeks; - } - - // region Class - View - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - - mDayNamesHeader = (LinearLayout) findViewById(R.id.cal_day_names); - mListViewWeeks = (WeekListView) findViewById(R.id.list_week); - mListViewWeeks.setLayoutManager(new LinearLayoutManager(getContext())); - mListViewWeeks.setHasFixedSize(true); - mListViewWeeks.setItemAnimator(null); - mListViewWeeks.setSnapEnabled(true); - - // display only two visible rows on the calendar view - getViewTreeObserver().addOnGlobalLayoutListener( - new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - if (getWidth() != 0 && getHeight() != 0) { - collapseCalendarView(); - getViewTreeObserver().removeGlobalOnLayoutListener(this); - } - } - } - ); - } - - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - - BusProvider.getInstance().toObserverable() - .subscribe(event -> { - if (event instanceof Events.CalendarScrolledEvent) { - expandCalendarView(); - } else if (event instanceof Events.AgendaListViewTouchedEvent) { - collapseCalendarView(); - } else if (event instanceof Events.DayClickedEvent) { - Events.DayClickedEvent clickedEvent = (Events.DayClickedEvent) event; - updateSelectedDay(clickedEvent.getCalendar(), clickedEvent.getDay()); - } - }); - } - - // endregion - - // region Public methods - - public void init(CalendarManager calendarManager, int dayTextColor, int currentDayTextColor, int pastDayTextColor, List eventList) { - Calendar today = calendarManager.getToday(); - Locale locale = calendarManager.getLocale(); - SimpleDateFormat weekDayFormatter = calendarManager.getWeekdayFormatter(); - List weeks = calendarManager.getWeeks(); - - setUpHeader(today, weekDayFormatter, locale); - setUpAdapter(today, weeks, dayTextColor, currentDayTextColor, pastDayTextColor, eventList); - scrollToDate(today, weeks); - } - - /** - * Fired when the Agenda list view changes section. - * - * @param calendarEvent The event for the selected position in the agenda listview. - */ - public void scrollToDate(final CalendarEvent calendarEvent) { - mListViewWeeks.post(()->scrollToPosition(updateSelectedDay(calendarEvent.getInstanceDay(), calendarEvent.getDayReference()))); - } - - public void scrollToDate(Calendar today, List weeks) { - Integer currentWeekIndex = null; - - for (int c = 0; c < weeks.size(); c++) { - if (DateHelper.sameWeek(today, weeks.get(c))) { - currentWeekIndex = c; - break; - } - } - - if (currentWeekIndex != null) { - final Integer finalCurrentWeekIndex = currentWeekIndex; - mListViewWeeks.post(() -> scrollToPosition(finalCurrentWeekIndex)); - } - } - - public void setBackgroundColor(int color) { - mListViewWeeks.setBackgroundColor(color); - } - - // endregion - - // region Private methods - - private void scrollToPosition(int targetPosition) { - LinearLayoutManager layoutManager = ((LinearLayoutManager) mListViewWeeks.getLayoutManager()); - layoutManager.scrollToPosition(targetPosition); - } - - private void updateItemAtPosition(int position) { - WeeksAdapter weeksAdapter = (WeeksAdapter) mListViewWeeks.getAdapter(); - weeksAdapter.notifyItemChanged(position); - } - - /** - * Creates a new adapter if necessary and sets up its parameters. - */ - private void setUpAdapter(Calendar today, List weeks, int dayTextColor, int currentDayTextColor, int pastDayTextColor, List events) { - BusProvider.getInstance().toObserverable() - .subscribe(event -> { - if (event instanceof Events.EventsFetched) { - //Log.d("CalendarView", "events size "+events.size()); - if (mWeeksAdapter == null) { - //Log.d(LOG_TAG, "Setting adapter with today's calendar: " + today.toString()); - mWeeksAdapter = new WeeksAdapter(getContext(), today, dayTextColor, currentDayTextColor, pastDayTextColor, events); - mListViewWeeks.setAdapter(mWeeksAdapter); - } - mWeeksAdapter.updateWeeksItems(weeks); - }}); - - } - - private void setUpHeader(Calendar today, SimpleDateFormat weekDayFormatter, Locale locale) { - int daysPerWeek = 7; - String[] dayLabels = new String[daysPerWeek]; - Calendar cal = Calendar.getInstance(CalendarManager.getInstance(getContext()).getLocale()); - cal.setTime(today.getTime()); - int firstDayOfWeek = cal.getFirstDayOfWeek(); - for (int count = 0; count < 7; count++) { - cal.set(Calendar.DAY_OF_WEEK, firstDayOfWeek + count); - if (locale.getLanguage().equals("en")) { - dayLabels[count] = weekDayFormatter.format(cal.getTime()).toUpperCase(locale); - } else { - dayLabels[count] = weekDayFormatter.format(cal.getTime()); - } - } - - for (int i = 0; i < mDayNamesHeader.getChildCount(); i++) { - TextView txtDay = (TextView) mDayNamesHeader.getChildAt(i); - txtDay.setText(dayLabels[i]); - } - } - - private void expandCalendarView() { - ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) getLayoutParams(); - layoutParams.height = (int) (getResources().getDimension(R.dimen.calendar_header_height) + 5 * getResources().getDimension(R.dimen.day_cell_height)); - setLayoutParams(layoutParams); - } - - private void collapseCalendarView() { - ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) getLayoutParams(); - layoutParams.height = (int) (getResources().getDimension(R.dimen.calendar_header_height) + 2 * getResources().getDimension(R.dimen.day_cell_height)); - setLayoutParams(layoutParams); - } - - /** - * Update a selected cell day item. - * - * @param calendar The Calendar instance of the day selected. - * @param dayItem The DayItem information held by the cell item. - * @return The selected row of the weeks list, to be updated. - */ - private int updateSelectedDay(Calendar calendar, IDayItem dayItem) { - Integer currentWeekIndex = null; - - // update highlighted/selected day - if (!dayItem.equals(getSelectedDay())) { - dayItem.setSelected(true); - if (getSelectedDay() != null) { - getSelectedDay().setSelected(false); - } - setSelectedDay(dayItem); - } - - for (int c = 0; c < CalendarManager.getInstance().getWeeks().size(); c++) { - if (DateHelper.sameWeek(calendar, CalendarManager.getInstance().getWeeks().get(c))) { - currentWeekIndex = c; - break; - } - } - - if (currentWeekIndex != null) { - // highlighted day has changed, update the rows concerned - if (currentWeekIndex != mCurrentListPosition) { - updateItemAtPosition(mCurrentListPosition); - } - mCurrentListPosition = currentWeekIndex; - updateItemAtPosition(currentWeekIndex); - } - - return mCurrentListPosition; - } - - // endregion -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/calendar/weekslist/WeekListView.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/calendar/weekslist/WeekListView.java deleted file mode 100644 index 099bc6eb..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/calendar/weekslist/WeekListView.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.github.tibolte.agendacalendarview.calendar.weekslist; - -import com.github.tibolte.agendacalendarview.utils.BusProvider; -import com.github.tibolte.agendacalendarview.utils.Events; - -import android.content.Context; -import androidx.recyclerview.widget.RecyclerView; -import android.util.AttributeSet; -import android.view.View; - -public class WeekListView extends RecyclerView { - private boolean mUserScrolling = false; - private boolean mScrolling = false; - - // region Constructors - - public WeekListView(Context context) { - super(context); - } - - public WeekListView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public WeekListView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - // endregion - - // region Public methods - - /** - * Enable snapping behaviour for this recyclerView - * - * @param enabled enable or disable the snapping behaviour - */ - public void setSnapEnabled(boolean enabled) { - if (enabled) { - addOnScrollListener(mScrollListener); - } else { - removeOnScrollListener(mScrollListener); - } - } - - // endregion - - // region Private methods - - private OnScrollListener mScrollListener = new OnScrollListener() { - @Override - public void onScrolled(RecyclerView recyclerView, int dx, int dy) { - super.onScrolled(recyclerView, dx, dy); - } - - @Override - public void onScrollStateChanged(RecyclerView recyclerView, int newState) { - super.onScrollStateChanged(recyclerView, newState); - final WeeksAdapter weeksAdapter = (WeeksAdapter) getAdapter(); - - switch (newState) { - case SCROLL_STATE_IDLE: - if (mUserScrolling) { - scrollToView(getCenterView()); - postDelayed(() -> weeksAdapter.setDragging(false), 700); // Wait for recyclerView to settle - } - - mUserScrolling = false; - mScrolling = false; - break; - // If scroll is caused by a touch (scroll touch, not any touch) - case SCROLL_STATE_DRAGGING: - BusProvider.getInstance().send(new Events.CalendarScrolledEvent()); - // If scroll was initiated already, this is not a user scrolling, but probably a tap, else set userScrolling - if (!mScrolling) { - mUserScrolling = true; - } - weeksAdapter.setDragging(true); - break; - case SCROLL_STATE_SETTLING: - // The user's finger is not touching the list anymore, no need - // for any alpha animation then - weeksAdapter.setAlphaSet(true); - mScrolling = true; - break; - } - } - }; - - private View getChildClosestToPosition(int y) { - if (getChildCount() <= 0) { - return null; - } - - int itemHeight = getChildAt(0).getMeasuredHeight(); - - int closestY = 9999; - View closestChild = null; - - for (int i = 0; i < getChildCount(); i++) { - View child = getChildAt(i); - - int childCenterY = ((int) child.getY() + (itemHeight / 2)); - int yDistance = childCenterY - y; - - // If child center is closer than previous closest, set it as closest - if (Math.abs(yDistance) < Math.abs(closestY)) { - closestY = yDistance; - closestChild = child; - } - } - - return closestChild; - } - - private View getCenterView() { - return getChildClosestToPosition(getMeasuredHeight() / 2); - } - - private void scrollToView(View child) { - if (child == null) { - return; - } - - stopScroll(); - - int scrollDistance = getScrollDistance(child); - - if (scrollDistance != 0) { - smoothScrollBy(0, scrollDistance); - } - } - - private int getScrollDistance(View child) { - int itemHeight = getChildAt(0).getMeasuredHeight(); - int centerY = getMeasuredHeight() / 2; - - int childCenterY = ((int) child.getY() + (itemHeight / 2)); - - return childCenterY - centerY; - } - - // endregion -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/calendar/weekslist/WeeksAdapter.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/calendar/weekslist/WeeksAdapter.java deleted file mode 100644 index df2177df..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/calendar/weekslist/WeeksAdapter.java +++ /dev/null @@ -1,321 +0,0 @@ -package com.github.tibolte.agendacalendarview.calendar.weekslist; - -import com.github.tibolte.agendacalendarview.CalendarManager; -import com.github.tibolte.agendacalendarview.R; -import com.github.tibolte.agendacalendarview.models.CalendarEvent; -import com.github.tibolte.agendacalendarview.models.IDayItem; -import com.github.tibolte.agendacalendarview.models.IWeekItem; -import com.github.tibolte.agendacalendarview.utils.BusProvider; -import com.github.tibolte.agendacalendarview.utils.DateHelper; -import com.github.tibolte.agendacalendarview.utils.Events; - -import android.animation.Animator; -import android.animation.AnimatorSet; -import android.animation.ObjectAnimator; -import android.content.Context; -import android.content.res.Resources; -import android.graphics.PorterDuff; -import android.graphics.PorterDuffColorFilter; -import android.graphics.Typeface; -import android.graphics.drawable.GradientDrawable; - -import androidx.recyclerview.widget.RecyclerView; - -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.FrameLayout; -import android.widget.LinearLayout; -import android.widget.TextView; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; - -public class WeeksAdapter extends RecyclerView.Adapter { - - public static final long FADE_DURATION = 250; - - private Context mContext; - private Calendar mToday; - private List mWeeksList = new ArrayList<>(); - private List mEventList = new ArrayList<>(); - private boolean mDragging; - private boolean mAlphaSet; - private int mDayTextColor, mPastDayTextColor, mCurrentDayColor; - - // region Constructor - - public WeeksAdapter(Context context, Calendar today, int dayTextColor, int currentDayTextColor, int pastDayTextColor, List events) { - this.mToday = today; - this.mContext = context; - this.mDayTextColor = dayTextColor; - this.mCurrentDayColor = currentDayTextColor; - this.mPastDayTextColor = pastDayTextColor; - this.mEventList = events; - } - - // endregion - - public void updateWeeksItems(List weekItems) { - this.mWeeksList.clear(); - this.mWeeksList.addAll(weekItems); - notifyDataSetChanged(); - } - - // region Getters/setters - - public List getWeeksList() { - return mWeeksList; - } - - public boolean isDragging() { - return mDragging; - } - - public void setDragging(boolean dragging) { - if (dragging != this.mDragging) { - this.mDragging = dragging; - notifyItemRangeChanged(0, mWeeksList.size()); - } - } - - public boolean isAlphaSet() { - return mAlphaSet; - } - - public void setAlphaSet(boolean alphaSet) { - mAlphaSet = alphaSet; - } - - // endregion - - // region RecyclerView.Adapter methods - - @Override - public WeekViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_week, parent, false); - return new WeekViewHolder(view); - } - - @Override - public void onBindViewHolder(WeekViewHolder weekViewHolder, int position) { - IWeekItem weekItem = mWeeksList.get(position); - weekViewHolder.bindWeek(weekItem, mToday); - } - - @Override - public int getItemCount() { - return mWeeksList.size(); - } - - // endregion - - // region Class - WeekViewHolder - - public class WeekViewHolder extends RecyclerView.ViewHolder { - - /** - * List of layout containers for each day - */ - private List mCells; - private TextView mTxtMonth; - private FrameLayout mMonthBackground; - - public WeekViewHolder(View itemView) { - super(itemView); - mTxtMonth = (TextView) itemView.findViewById(R.id.month_label); - mMonthBackground = (FrameLayout) itemView.findViewById(R.id.month_background); - LinearLayout daysContainer = (LinearLayout) itemView.findViewById(R.id.week_days_container); - setUpChildren(daysContainer); - } - - public void bindWeek(IWeekItem weekItem, Calendar today) { - setUpMonthOverlay(); - - List dayItems = weekItem.getDayItems(); - - for (int c = 0; c < dayItems.size(); c++) { - final IDayItem dayItem = dayItems.get(c); - LinearLayout cellItem = mCells.get(c); - TextView txtDay = (TextView) cellItem.findViewById(R.id.view_day_day_label); - TextView txtMonth = (TextView) cellItem.findViewById(R.id.view_day_month_label); - View circleView = cellItem.findViewById(R.id.view_day_circle_selected); - View eventIndicator1 = cellItem.findViewById(R.id.view_day_event_indicator1); - View eventIndicator2 = cellItem.findViewById(R.id.view_day_event_indicator2); - View eventIndicator3 = cellItem.findViewById(R.id.view_day_event_indicator3); - cellItem.setOnClickListener(v->BusProvider.getInstance().send(new Events.DayClickedEvent(dayItem))); - - eventIndicator1.setVisibility(View.INVISIBLE); - eventIndicator2.setVisibility(View.INVISIBLE); - eventIndicator3.setVisibility(View.INVISIBLE); - - Calendar dayItemCalendar = Calendar.getInstance(); - dayItemCalendar.setTime(dayItem.getDate()); - int eventCount = 0; - for (CalendarEvent event: mEventList) { - if (event.getStartTime().get(Calendar.YEAR) == dayItemCalendar.get(Calendar.YEAR) - && event.getStartTime().get(Calendar.MONTH) == dayItemCalendar.get(Calendar.MONTH) - && event.getStartTime().get(Calendar.DAY_OF_MONTH) == dayItemCalendar.get(Calendar.DAY_OF_MONTH)) { - eventCount++; - if (eventCount == 1) { - eventIndicator1.setVisibility(View.VISIBLE); - eventIndicator1.getBackground().setColorFilter(new PorterDuffColorFilter(event.getColor(),PorterDuff.Mode.MULTIPLY)); - } - if (eventCount == 2) { - eventIndicator2.setVisibility(View.VISIBLE); - eventIndicator2.getBackground().setColorFilter(new PorterDuffColorFilter(event.getColor(),PorterDuff.Mode.MULTIPLY)); - } - if (eventCount == 3) { - eventIndicator3.setVisibility(View.VISIBLE); - eventIndicator3.getBackground().setColorFilter(new PorterDuffColorFilter(event.getColor(),PorterDuff.Mode.MULTIPLY)); - } - } - } - - //Log.d("CalendarView", "Event count for day "+dayItem.getValue()+" is "+eventCount); - - txtMonth.setVisibility(View.GONE); - txtDay.setTextColor(mDayTextColor); - txtMonth.setTextColor(mDayTextColor); - circleView.setVisibility(View.GONE); - - txtDay.setTypeface(null, Typeface.NORMAL); - txtMonth.setTypeface(null, Typeface.NORMAL); - - // Display the day - txtDay.setText(Integer.toString(dayItem.getValue())); - - // Highlight first day of the month - if (dayItem.isFirstDayOfTheMonth() && !dayItem.isSelected()) { - txtMonth.setVisibility(View.VISIBLE); - txtMonth.setText(dayItem.getMonth()); - txtDay.setTypeface(null, Typeface.BOLD); - txtMonth.setTypeface(null, Typeface.BOLD); - } - - // Check if this day is in the past - if (today.getTime().after(dayItem.getDate()) && !DateHelper.sameDate(today, dayItem.getDate())) { - txtDay.setTextColor(mPastDayTextColor); - txtMonth.setTextColor(mPastDayTextColor); - } - - // Highlight the cell if this day is today - if (dayItem.isToday() && !dayItem.isSelected()) { - txtDay.setTextColor(mCurrentDayColor); - } - - if (dayItem.getShowBadge()) { - circleView.setVisibility(View.VISIBLE); - GradientDrawable drawable = (GradientDrawable) circleView.getBackground(); - drawable.setStroke((int) (2 * Resources.getSystem().getDisplayMetrics().density), 0xffff0000); - } - - // Show a circle if the day is selected - if (dayItem.isSelected()) { - txtDay.setTextColor(mDayTextColor); - circleView.setVisibility(View.VISIBLE); - GradientDrawable drawable = (GradientDrawable) circleView.getBackground(); - drawable.setStroke((int) (1 * Resources.getSystem().getDisplayMetrics().density), mDayTextColor); - } - - // Check if the month label has to be displayed - if (dayItem.getValue() == 15) { - mTxtMonth.setVisibility(View.VISIBLE); - SimpleDateFormat monthDateFormat = new SimpleDateFormat(mContext.getResources().getString(R.string.month_name_format), CalendarManager.getInstance().getLocale()); - String month = monthDateFormat.format(weekItem.getDate()).toUpperCase(); - if (today.get(Calendar.YEAR) != weekItem.getYear()) { - month = month + String.format(" %d", weekItem.getYear()); - } - mTxtMonth.setText(month); - } - } - } - - private void setUpChildren(LinearLayout daysContainer) { - mCells = new ArrayList<>(); - for (int i = 0; i < daysContainer.getChildCount(); i++) { - mCells.add((LinearLayout) daysContainer.getChildAt(i)); - } - } - - private void setUpMonthOverlay() { - mTxtMonth.setVisibility(View.GONE); - - if (isDragging()) { - AnimatorSet animatorSetFadeIn = new AnimatorSet(); - animatorSetFadeIn.setDuration(FADE_DURATION); - ObjectAnimator animatorTxtAlphaIn = ObjectAnimator.ofFloat(mTxtMonth, "alpha", mTxtMonth.getAlpha(), 1f); - ObjectAnimator animatorBackgroundAlphaIn = ObjectAnimator.ofFloat(mMonthBackground, "alpha", mMonthBackground.getAlpha(), 1f); - animatorSetFadeIn.playTogether( - animatorTxtAlphaIn - //animatorBackgroundAlphaIn - ); - animatorSetFadeIn.addListener(new Animator.AnimatorListener() { - @Override - public void onAnimationStart(Animator animation) { - - } - - @Override - public void onAnimationEnd(Animator animation) { - setAlphaSet(true); - } - - @Override - public void onAnimationCancel(Animator animation) { - - } - - @Override - public void onAnimationRepeat(Animator animation) { - - } - }); - animatorSetFadeIn.start(); - } else { - AnimatorSet animatorSetFadeOut = new AnimatorSet(); - animatorSetFadeOut.setDuration(FADE_DURATION); - ObjectAnimator animatorTxtAlphaOut = ObjectAnimator.ofFloat(mTxtMonth, "alpha", mTxtMonth.getAlpha(), 0f); - ObjectAnimator animatorBackgroundAlphaOut = ObjectAnimator.ofFloat(mMonthBackground, "alpha", mMonthBackground.getAlpha(), 0f); - animatorSetFadeOut.playTogether( - animatorTxtAlphaOut - //animatorBackgroundAlphaOut - ); - animatorSetFadeOut.addListener(new Animator.AnimatorListener() { - @Override - public void onAnimationStart(Animator animation) { - - } - - @Override - public void onAnimationEnd(Animator animation) { - setAlphaSet(false); - } - - @Override - public void onAnimationCancel(Animator animation) { - - } - - @Override - public void onAnimationRepeat(Animator animation) { - - } - }); - animatorSetFadeOut.start(); - } - - if (isAlphaSet()) { - //mMonthBackground.setAlpha(1f); - mTxtMonth.setAlpha(1f); - } else { - //mMonthBackground.setAlpha(0f); - mTxtMonth.setAlpha(0f); - } - } - } - - // endregion -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/BaseCalendarEvent.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/BaseCalendarEvent.java deleted file mode 100644 index 642eea2c..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/BaseCalendarEvent.java +++ /dev/null @@ -1,345 +0,0 @@ -package com.github.tibolte.agendacalendarview.models; - -import java.util.Calendar; - -/** - * Event model class containing the information to be displayed on the agenda view. - */ -public class BaseCalendarEvent implements CalendarEvent { - - /** - * Id of the event. - */ - private long mId; - /** - * Color to be displayed in the agenda view. - */ - private int mColor; - /** - * Text color displayed on the background color - */ - private int mTextColor; - /** - * Title of the event. - */ - private String mTitle; - /** - * Description of the event. - */ - private String mDescription; - /** - * Where the event takes place. - */ - private String mLocation; - /** - * Calendar instance helping sorting the events per section in the agenda view. - */ - private Calendar mInstanceDay; - /** - * Start time of the event. - */ - private Calendar mStartTime; - /** - * End time of the event. - */ - private Calendar mEndTime; - /** - * Indicates if the event lasts all day. - */ - private boolean mAllDay; - /** - * Tells if this BaseCalendarEvent instance is used as a placeholder in the agenda view, if there's - * no event for that day. - */ - private boolean mPlaceHolder; - /** - * Tells if this BaseCalendarEvent instance is used as a forecast information holder in the agenda - * view. - */ - private boolean mWeather; - /** - * Duration of the event. - */ - private String mDuration; - /** - * References to a DayItem instance for that event, used to link interaction between the - * calendar view and the agenda view. - */ - private IDayItem mDayReference; - /** - * References to a WeekItem instance for that event, used to link interaction between the - * calendar view and the agenda view. - */ - private IWeekItem mWeekReference; - /** - * Weather icon string returned by the Dark Sky API. - */ - private String mWeatherIcon; - /** - * Temperature value returned by the Dark Sky API. - */ - private double mTemperature; - - private boolean mShowBadge; - - // region Constructor - - /** - * Initializes the event - * - * @param id The id of the event. - * @param color The color of the event. - * @param textColor The color of the event description text. - * @param title The title of the event. - * @param description The description of the event. - * @param location The location of the event. - * @param dateStart The start date of the event. - * @param dateEnd The end date of the event. - * @param allDay Int that can be equal to 0 or 1. - * @param duration The duration of the event in RFC2445 format. - */ - public BaseCalendarEvent(long id, int color, int textColor, String title, String description, String location, long dateStart, long dateEnd, int allDay, String duration) { - this.mId = id; - this.mColor = color; - this.mTextColor = textColor; - this.mAllDay = (allDay == 1); - this.mDuration = duration; - this.mTitle = title; - this.mDescription = description; - this.mLocation = location; - - this.mStartTime = Calendar.getInstance(); - this.mStartTime.setTimeInMillis(dateStart); - this.mEndTime = Calendar.getInstance(); - this.mEndTime.setTimeInMillis(dateEnd); - } - - public BaseCalendarEvent() { - - } - - /** - * Initializes the event - * @param title The title of the event. - * @param description The description of the event. - * @param location The location of the event. - * @param color The color of the event (for display in the app). - * @param textColor The color of the event description text. - * @param startTime The start time of the event. - * @param endTime The end time of the event. - * @param allDay Indicates if the event lasts the whole day. - */ - public BaseCalendarEvent(String title, String description, String location, int color, int textColor, Calendar startTime, Calendar endTime, boolean allDay) { - this.mTitle = title; - this.mDescription = description; - this.mLocation = location; - this.mColor = color; - this.mTextColor = textColor; - this.mStartTime = startTime; - this.mEndTime = endTime; - this.mAllDay = allDay; - } - - public BaseCalendarEvent(String title, String description, String location, int color, int textColor, Calendar startTime, Calendar endTime, boolean allDay, long id, boolean showBadge) { - this.mTitle = title; - this.mDescription = description; - this.mLocation = location; - this.mColor = color; - this.mTextColor = textColor; - this.mStartTime = startTime; - this.mEndTime = endTime; - this.mAllDay = allDay; - this.mId = id; - this.mShowBadge = showBadge; - } - - public BaseCalendarEvent(BaseCalendarEvent calendarEvent) { - this.mId = calendarEvent.getId(); - this.mColor = calendarEvent.getColor(); - this.mTextColor = calendarEvent.getTextColor(); - this.mAllDay = calendarEvent.isAllDay(); - this.mDuration = calendarEvent.getDuration(); - this.mTitle = calendarEvent.getTitle(); - this.mDescription = calendarEvent.getDescription(); - this.mLocation = calendarEvent.getLocation(); - this.mStartTime = calendarEvent.getStartTime(); - this.mEndTime = calendarEvent.getEndTime(); - this.mShowBadge = calendarEvent.getShowBadge(); - } - - // endregion - - // region Getters/Setters - - public int getColor() { - return mColor; - } - - public void setColor(int mColor) { - this.mColor = mColor; - } - - public int getTextColor() { - return mTextColor; - } - - public void setTextColor(int mTextColor) { - this.mTextColor = mTextColor; - } - - public String getDescription() { - return mDescription; - } - - public boolean isAllDay() { - return mAllDay; - } - - public void setAllDay(boolean allDay) { - this.mAllDay = allDay; - } - - public void setDescription(String mDescription) { - this.mDescription = mDescription; - } - - public Calendar getInstanceDay() { - return mInstanceDay; - } - - public void setInstanceDay(Calendar mInstanceDay) { - this.mInstanceDay = mInstanceDay; - this.mInstanceDay.set(Calendar.HOUR, 0); - this.mInstanceDay.set(Calendar.MINUTE, 0); - this.mInstanceDay.set(Calendar.SECOND, 0); - this.mInstanceDay.set(Calendar.MILLISECOND, 0); - this.mInstanceDay.set(Calendar.AM_PM, 0); - } - - public Calendar getEndTime() { - return mEndTime; - } - - public void setEndTime(Calendar mEndTime) { - this.mEndTime = mEndTime; - } - public void setPlaceholder(boolean placeholder) { - mPlaceHolder = placeholder; - } - public boolean isPlaceholder() { - return mPlaceHolder; - } - - public long getId() { - return mId; - } - - public void setId(long mId) { - this.mId = mId; - } - - public boolean getShowBadge() { - return mShowBadge; - } - - public void setShowBadge(boolean mShowBadge) { - this.mShowBadge = mShowBadge; - } - - public String getLocation() { - return mLocation; - } - - public void setLocation(String mLocation) { - this.mLocation = mLocation; - } - - public Calendar getStartTime() { - return mStartTime; - } - - public void setStartTime(Calendar mStartTime) { - this.mStartTime = mStartTime; - } - - public String getTitle() { - return mTitle; - } - - public void setTitle(String mTitle) { - this.mTitle = mTitle; - } - - public String getDuration() { - return mDuration; - } - - public void setDuration(String duration) { - this.mDuration = duration; - } - - public boolean isPlaceHolder() { - return mPlaceHolder; - } - - public void setPlaceHolder(boolean mPlaceHolder) { - this.mPlaceHolder = mPlaceHolder; - } - - public boolean isWeather() { - return mWeather; - } - - public void setWeather(boolean mWeather) { - this.mWeather = mWeather; - } - - public IDayItem getDayReference() { - return mDayReference; - } - - public void setDayReference(IDayItem mDayReference) { - this.mDayReference = mDayReference; - } - - public IWeekItem getWeekReference() { - return mWeekReference; - } - - public void setWeekReference(IWeekItem mWeekReference) { - this.mWeekReference = mWeekReference; - } - - public String getWeatherIcon() { - return mWeatherIcon; - } - - public void setWeatherIcon(String mWeatherIcon) { - this.mWeatherIcon = mWeatherIcon; - } - - public double getTemperature() { - return mTemperature; - } - - public void setTemperature(double mTemperature) { - this.mTemperature = mTemperature; - } - - @Override - public CalendarEvent copy() { - return new BaseCalendarEvent(this); - } - - // endregion - - @Override - public String toString() { - return "BaseCalendarEvent{" - + "title='" - + mTitle - + ", instanceDay= " - + mInstanceDay.getTime() - + "}"; - } -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/CalendarEvent.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/CalendarEvent.java deleted file mode 100644 index 05df9a0f..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/CalendarEvent.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.github.tibolte.agendacalendarview.models; - -import java.util.Calendar; - -public interface CalendarEvent { - - - void setPlaceholder(boolean placeholder); - - boolean isPlaceholder(); - - public String getLocation(); - - public void setLocation(String mLocation); - - long getId(); - - void setId(long mId); - - boolean getShowBadge(); - - void setShowBadge(boolean mShowBadge); - - int getTextColor(); - - void setTextColor(int mTextColor); - - String getDescription(); - - void setDescription(String mDescription); - - boolean isAllDay(); - - void setAllDay(boolean allDay); - - Calendar getStartTime(); - - void setStartTime(Calendar mStartTime); - - Calendar getEndTime(); - - void setEndTime(Calendar mEndTime); - - String getTitle(); - - void setTitle(String mTitle); - - Calendar getInstanceDay(); - - void setInstanceDay(Calendar mInstanceDay); - - IDayItem getDayReference(); - - void setDayReference(IDayItem mDayReference); - - IWeekItem getWeekReference(); - - void setWeekReference(IWeekItem mWeekReference); - - CalendarEvent copy(); - - int getColor(); -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/DayItem.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/DayItem.java deleted file mode 100644 index 39be4985..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/DayItem.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.github.tibolte.agendacalendarview.models; - -import com.github.tibolte.agendacalendarview.CalendarManager; -import com.github.tibolte.agendacalendarview.utils.DateHelper; - -import java.util.Calendar; -import java.util.Date; - -/** - * Day model class. - */ -public class DayItem implements IDayItem { - private Date mDate; - private int mValue; - private int mDayOfTheWeek; - private boolean mToday; - private boolean mFirstDayOfTheMonth; - private boolean mSelected; - private String mMonth; - private boolean mShowBadge; - - // region Constructor - - public DayItem(Date date, int value, boolean today, String month) { - this.mDate = date; - this.mValue = value; - this.mToday = today; - this.mMonth = month; - } - // only for cleanDay - public DayItem() { - - } - public DayItem(DayItem original) { - - this.mDate = original.getDate(); - this.mValue = original.getValue(); - this.mToday = original.isToday(); - this.mDayOfTheWeek = original.getDayOftheWeek(); - this.mFirstDayOfTheMonth = original.isFirstDayOfTheMonth(); - this.mSelected = original.isSelected(); - this.mMonth = original.getMonth(); - this.mShowBadge = original.mShowBadge; - } - // endregion - - // region Getters/Setters - - public Date getDate() { - return mDate; - } - - public void setDate(Date date) { - this.mDate = date; - } - - public int getValue() { - return mValue; - } - - public void setValue(int value) { - this.mValue = value; - } - - public boolean isToday() { - return mToday; - } - - public void setToday(boolean today) { - this.mToday = today; - } - - public boolean isSelected() { - return mSelected; - } - - public void setSelected(boolean selected) { - this.mSelected = selected; - } - - public boolean isFirstDayOfTheMonth() { - return mFirstDayOfTheMonth; - } - - public void setFirstDayOfTheMonth(boolean firstDayOfTheMonth) { - this.mFirstDayOfTheMonth = firstDayOfTheMonth; - } - - public String getMonth() { - return mMonth; - } - - public void setMonth(String month) { - this.mMonth = month; - } - - public int getDayOftheWeek() { - return mDayOfTheWeek; - } - - public void setDayOftheWeek(int mDayOftheWeek) { - this.mDayOfTheWeek = mDayOftheWeek; - } - - public void setShowBadge(boolean showBadge) { - this.mShowBadge = showBadge; - } - - public boolean getShowBadge() { - return this.mShowBadge; - } - - // region Public methods - - public void buildDayItemFromCal(Calendar calendar) { - Date date = calendar.getTime(); - this.mDate = date; - - this.mValue = calendar.get(Calendar.DAY_OF_MONTH); - this.mToday = DateHelper.sameDate(calendar, CalendarManager.getInstance().getToday()); - this.mMonth = CalendarManager.getInstance().getMonthHalfNameFormat().format(date); - if (this.mValue == 1) { - this.mFirstDayOfTheMonth = true; - } - } - - // endregion - - @Override - public String toString() { - return "DayItem{" - + "Date='" - + mDate.toString() - + ", value=" - + mValue - + '}'; - } - - @Override - public IDayItem copy() { - return new DayItem(this); - } - - // endregion -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/IDayItem.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/IDayItem.java deleted file mode 100644 index acfe3c76..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/IDayItem.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.github.tibolte.agendacalendarview.models; - -import java.util.Calendar; -import java.util.Date; - -public interface IDayItem { - - // region Getters/Setters - - Date getDate(); - - void setDate(Date date); - - int getValue(); - - void setValue(int value); - - boolean isToday(); - - void setToday(boolean today); - - boolean isSelected(); - - void setSelected(boolean selected); - - boolean isFirstDayOfTheMonth(); - - void setFirstDayOfTheMonth(boolean firstDayOfTheMonth); - - String getMonth(); - - void setMonth(String month); - - int getDayOftheWeek(); - - void setDayOftheWeek(int mDayOftheWeek); - - // endregion - - void buildDayItemFromCal(Calendar calendar); - - String toString(); - - IDayItem copy(); - - void setShowBadge(boolean showBadge); - - boolean getShowBadge(); -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/IWeekItem.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/IWeekItem.java deleted file mode 100644 index bb08b89a..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/IWeekItem.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.tibolte.agendacalendarview.models; - -import java.util.Date; -import java.util.List; - -public interface IWeekItem { - - - int getWeekInYear(); - - void setWeekInYear(int weekInYear); - - int getYear(); - - void setYear(int year); - - int getMonth(); - - void setMonth(int month); - - Date getDate(); - - void setDate(Date date); - - String getLabel(); - - void setLabel(String label); - - List getDayItems(); - - void setDayItems(List dayItems); - - IWeekItem copy(); -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/WeekItem.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/WeekItem.java deleted file mode 100644 index 40b94902..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/models/WeekItem.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.github.tibolte.agendacalendarview.models; - -import java.util.Date; -import java.util.List; - -/** - * Week model class. - */ -public class WeekItem implements IWeekItem { - private int mWeekInYear; - private int mYear; - private int mMonth; - private Date mDate; - private String mLabel; - private List mDayItems; - - // region Constructor - - public WeekItem(int weekInYear, int year, Date date, String label, int month) { - this.mWeekInYear = weekInYear; - this.mYear = year; - this.mDate = date; - this.mLabel = label; - this.mMonth = month; - } - public WeekItem(WeekItem original) { - this.mWeekInYear = original.getWeekInYear(); - this.mYear = original.getYear(); - this.mMonth = original.getMonth(); - this.mDate = original.getDate(); - this.mLabel = original.getLabel(); - this.mDayItems = original.getDayItems(); - } - - public WeekItem(){ - - } - - // endregion - - // region Getters/Setters - - public int getWeekInYear() { - return mWeekInYear; - } - - public void setWeekInYear(int weekInYear) { - this.mWeekInYear = weekInYear; - } - - public int getYear() { - return mYear; - } - - public void setYear(int year) { - this.mYear = year; - } - - public int getMonth() { - return mMonth; - } - - public void setMonth(int month) { - this.mMonth = month; - } - - public Date getDate() { - return mDate; - } - - public void setDate(Date date) { - this.mDate = date; - } - - public String getLabel() { - return mLabel; - } - - public void setLabel(String label) { - this.mLabel = label; - } - - public List getDayItems() { - return mDayItems; - } - - public void setDayItems(List dayItems) { - this.mDayItems = dayItems; - } - - @Override - public IWeekItem copy() { - return new WeekItem(this); - } - - // endregion - - @Override - public String toString() { - return "WeekItem{" - + "label='" - + mLabel - + '\'' - + ", weekInYear=" - + mWeekInYear - + ", year=" - + mYear - + '}'; - } -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/render/DefaultEventRenderer.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/render/DefaultEventRenderer.java deleted file mode 100644 index 729ad706..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/render/DefaultEventRenderer.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.github.tibolte.agendacalendarview.render; - -import android.content.Context; -import android.content.res.Resources; -import androidx.annotation.NonNull; -import androidx.cardview.widget.CardView; -import androidx.core.content.ContextCompat; - -import android.graphics.Color; -import android.util.TypedValue; -import android.view.View; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.github.tibolte.agendacalendarview.R; -import com.github.tibolte.agendacalendarview.models.BaseCalendarEvent; -import com.google.android.material.internal.ViewUtils; - -/** - * Class helping to inflate our default layout in the AgendaAdapter - */ -public class DefaultEventRenderer extends EventRenderer { - - public static int themeAttributeToColor(int themeAttributeId, - Context context, - int fallbackColorId) { - TypedValue outValue = new TypedValue(); - Resources.Theme theme = context.getTheme(); - boolean wasResolved = - theme.resolveAttribute( - themeAttributeId, outValue, true); - if (wasResolved) { - return ContextCompat.getColor( - context, outValue.resourceId); - } else { - // fallback colour handling - return fallbackColorId; - } - } - - // region class - EventRenderer - - @Override - public void render(@NonNull View view, @NonNull BaseCalendarEvent event) { - CardView card = view.findViewById(R.id.view_agenda_event_card_view); - TextView txtTitle = view.findViewById(R.id.view_agenda_event_title); - TextView txtLocation = view.findViewById(R.id.view_agenda_event_location); - LinearLayout descriptionContainer = view.findViewById(R.id.view_agenda_event_description_container); - LinearLayout locationContainer = view.findViewById(R.id.view_agenda_event_location_container); - - descriptionContainer.setVisibility(View.VISIBLE); - - txtTitle.setText(event.getTitle()); - txtLocation.setText(event.getLocation()); - if (event.getLocation().length() > 0) { - locationContainer.setVisibility(View.VISIBLE); - txtLocation.setText(event.getLocation()); - } else { - locationContainer.setVisibility(View.GONE); - } - - if (!event.isPlaceholder()/*!event.getTitle().equals(view.getResources().getString(R.string.agenda_event_no_events))*/) { - txtTitle.setTextColor(event.getTextColor()); - card.setCardBackgroundColor(event.getColor()); - txtLocation.setTextColor(event.getTextColor()); - } - else { - card.setCardBackgroundColor(Color.TRANSPARENT); - card.setCardElevation(0); - card.setBackgroundColor(Color.TRANSPARENT); - card.setRadius(0); - card.setBackgroundDrawable(null); - } - } - - @Override - public int getEventLayout() { - return R.layout.view_agenda_event; - } - - // endregion -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/render/EventRenderer.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/render/EventRenderer.java deleted file mode 100644 index e62f23b5..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/render/EventRenderer.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.tibolte.agendacalendarview.render; - -import androidx.annotation.LayoutRes; -import android.view.View; - -import com.github.tibolte.agendacalendarview.models.CalendarEvent; - -import java.lang.reflect.ParameterizedType; - -/** - * Base class for helping layout rendering - */ -public abstract class EventRenderer { - public abstract void render(final View view, final T event); - - @LayoutRes - public abstract int getEventLayout(); - - public Class getRenderType() { - ParameterizedType type = (ParameterizedType) getClass().getGenericSuperclass(); - return (Class) type.getActualTypeArguments()[0]; - } -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/utils/BusProvider.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/utils/BusProvider.java deleted file mode 100644 index 99bdbf3d..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/utils/BusProvider.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.tibolte.agendacalendarview.utils; - -import rx.Observable; -import rx.subjects.PublishSubject; -import rx.subjects.SerializedSubject; -import rx.subjects.Subject; - -public class BusProvider { - - public static BusProvider mInstance; - - private final Subject mBus = new SerializedSubject<>(PublishSubject.create()); - - // region Constructors - - public static BusProvider getInstance() { - if (mInstance == null) { - mInstance = new BusProvider(); - } - return mInstance; - } - - // endregion - - // region Public methods - - public void send(Object object) { - mBus.onNext(object); - } - - public Observable toObserverable() { - return mBus; - } - - // endregion -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/utils/DateHelper.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/utils/DateHelper.java deleted file mode 100644 index f9439d04..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/utils/DateHelper.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.github.tibolte.agendacalendarview.utils; - -import com.github.tibolte.agendacalendarview.CalendarManager; -import com.github.tibolte.agendacalendarview.R; -import com.github.tibolte.agendacalendarview.models.IWeekItem; - -import android.content.Context; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.Locale; -import java.util.concurrent.TimeUnit; - -/** - * Class containing helper functions for dates - */ -public class DateHelper { - - // region Public methods - - /** - * Check if two Calendar instances have the same time (by month, year and day of month) - * - * @param cal The first Calendar instance. - * @param selectedDate The second Calendar instance. - * @return True if both instances have the same time. - */ - public static boolean sameDate(Calendar cal, Calendar selectedDate) { - return cal.get(Calendar.MONTH) == selectedDate.get(Calendar.MONTH) - && cal.get(Calendar.YEAR) == selectedDate.get(Calendar.YEAR) - && cal.get(Calendar.DAY_OF_MONTH) == selectedDate.get(Calendar.DAY_OF_MONTH); - } - - /** - * Check if a Date instance and a Calendar instance have the same time (by month, year and day - * of month) - * - * @param cal The Calendar instance. - * @param selectedDate The Date instance. - * @return True if both have the same time. - */ - public static boolean sameDate(Calendar cal, Date selectedDate) { - Calendar selectedCal = Calendar.getInstance(); - selectedCal.setTime(selectedDate); - return cal.get(Calendar.MONTH) == selectedCal.get(Calendar.MONTH) - && cal.get(Calendar.YEAR) == selectedCal.get(Calendar.YEAR) - && cal.get(Calendar.DAY_OF_MONTH) == selectedCal.get(Calendar.DAY_OF_MONTH); - } - - /** - * Check if a Date instance is between two Calendar instances' dates (inclusively) in time. - * - * @param selectedDate The date to verify. - * @param startCal The start time. - * @param endCal The end time. - * @return True if the verified date is between the two specified dates. - */ - public static boolean isBetweenInclusive(Date selectedDate, Calendar startCal, Calendar endCal) { - Calendar selectedCal = Calendar.getInstance(); - selectedCal.setTime(selectedDate); - // Check if we deal with the same day regarding startCal and endCal - return sameDate(selectedCal, startCal) || selectedCal.after(startCal) && selectedCal.before(endCal); - } - - /** - * Check if Calendar instance's date is in the same week, as the WeekItem instance. - * - * @param cal The Calendar instance to verify. - * @param week The WeekItem instance to compare to. - * @return True if both instances are in the same week. - */ - public static boolean sameWeek(Calendar cal, IWeekItem week) { - return (cal.get(Calendar.WEEK_OF_YEAR) == week.getWeekInYear() && cal.get(Calendar.YEAR) == week.getYear()); - } - - /** - * Convert a millisecond duration to a string format - * - * @param millis A duration to convert to a string form - * @return A string of the form "Xd" or either "XhXm". - */ - public static String getDuration(Context context, long millis) { - if (millis < 0) { - throw new IllegalArgumentException("Duration must be greater than zero!"); - } - - long days = TimeUnit.MILLISECONDS.toDays(millis); - millis -= TimeUnit.DAYS.toMillis(days); - long hours = TimeUnit.MILLISECONDS.toHours(millis); - millis -= TimeUnit.HOURS.toMillis(hours); - long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); - - StringBuilder sb = new StringBuilder(64); - if (days > 0) { - sb.append(days); - sb.append(context.getResources().getString(R.string.agenda_event_day_duration)); - return (sb.toString()); - } else { - if (hours > 0) { - sb.append(hours); - sb.append("h"); - } - if (minutes > 0) { - sb.append(minutes); - sb.append("m"); - } - } - - return (sb.toString()); - } - - /** - * Used for displaying the date in any section of the agenda view. - * - * @param calendar The date of the section. - * @param locale The locale used by the Sunrise calendar. - * @return The formatted date without the year included. - */ - public static String getYearLessLocalizedDate(Calendar calendar, Locale locale) { - SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.FULL, CalendarManager.getInstance().getLocale()); - String pattern = sdf.toPattern(); - - String yearLessPattern = pattern.replaceAll("\\W?[Yy]+\\W?", ""); - SimpleDateFormat yearLessSDF = new SimpleDateFormat(yearLessPattern, locale); - String yearLessDate = yearLessSDF.format(calendar.getTime()).toUpperCase(); - if (yearLessDate.endsWith(",")) { - yearLessDate = yearLessDate.substring(0, yearLessDate.length() - 1); - } - return yearLessDate; - } - - // endregion -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/utils/Events.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/utils/Events.java deleted file mode 100644 index 98d13f20..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/utils/Events.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.github.tibolte.agendacalendarview.utils; - -import com.github.tibolte.agendacalendarview.models.IDayItem; - -import java.util.Calendar; - -/** - * Events emitted by the bus provider. - */ -public class Events { - - public static class DayClickedEvent { - - public Calendar mCalendar; - public IDayItem mDayItem; - - public DayClickedEvent(IDayItem dayItem) { - this.mCalendar = Calendar.getInstance(); - this.mCalendar.setTime(dayItem.getDate()); - this.mDayItem = dayItem; - } - - public Calendar getCalendar() { - return mCalendar; - } - - public IDayItem getDay() { - return mDayItem; - } - } - - public static class CalendarScrolledEvent { - } - - public static class AgendaListViewTouchedEvent { - } - - public static class EventsFetched { - } - - public static class ForecastFetched { - } -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/utils/ListViewScrollTracker.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/utils/ListViewScrollTracker.java deleted file mode 100644 index 47e16de3..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/utils/ListViewScrollTracker.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.github.tibolte.agendacalendarview.utils; - -import com.github.tibolte.agendacalendarview.agenda.AgendaListView; - -import android.util.SparseArray; -import android.view.View; - -/** - * Helper class calculating the scrolling distance in the AgendaListView. - */ -public class ListViewScrollTracker { - private AgendaListView mListView; - private SparseArray mPositions; - private SparseArray mListViewItemHeights = new SparseArray<>(); - private int mFirstVisiblePosition; - private int mReferencePosition = -1; // Position of the current date in the Agenda listView - - // region Constructor and Accessor(s) - - public ListViewScrollTracker(AgendaListView listView) { - mListView = listView; - } - - public int getReferencePosition() { - return mReferencePosition; - } - - // endregion - - // region Public methods - - /** - * Call from an AbsListView.OnScrollListener to calculate the incremental offset (change in - * scroll offset - * since the last calculation). - * - * @param firstVisiblePosition First visible item position in the list. - * @param visibleItemCount Number of visible items in the list. - * @return The incremental offset, or 0 if it wasn't possible to calculate the offset. - */ - public int calculateIncrementalOffset(int firstVisiblePosition, int visibleItemCount) { - // Remember previous positions, if any - SparseArray previousPositions = mPositions; - - // Store new positions - mPositions = new SparseArray<>(); - for (int i = 0; i < visibleItemCount; i++) { - mPositions.put(firstVisiblePosition + i, mListView.getListChildAt(i).getTop()); - } - - if (previousPositions != null) { - // Find position which exists in both mPositions and previousPositions, then return the difference - // of the new and old Y values. - for (int i = 0; i < previousPositions.size(); i++) { - int previousPosition = previousPositions.keyAt(i); - int previousTop = previousPositions.get(previousPosition); - Integer newTop = mPositions.get(previousPosition); - if (newTop != null) { - return newTop - previousTop; - } - } - } - - return 0; // No view's position was in both previousPositions and mPositions - } - - /** - * Call from an AbsListView.OnScrollListener to calculate the scrollY (Here - * we definite as the distance in pixels compared to the position representing the current - * date). - * - * @param firstVisiblePosition First visible item position in the list. - * @param visibleItemCount Number of visible items in the list. - * @return Distance in pixels compared to current day position (negative if firstVisiblePosition less than mReferencePosition) - */ - public int calculateScrollY(int firstVisiblePosition, int visibleItemCount) { - mFirstVisiblePosition = firstVisiblePosition; - if (mReferencePosition < 0) { - mReferencePosition = mFirstVisiblePosition; - } - - if (visibleItemCount > 0) { - View c = mListView.getListChildAt(0); // this is the first visible row - int scrollY = -c.getTop(); - mListViewItemHeights.put(firstVisiblePosition, c.getMeasuredHeight()); - - if (mFirstVisiblePosition >= mReferencePosition) { - for (int i = mReferencePosition; i < firstVisiblePosition; ++i) { - if (mListViewItemHeights.get(i) == null) { - mListViewItemHeights.put(i, c.getMeasuredHeight()); - } - scrollY += mListViewItemHeights.get(i); // add all heights of the views that are gone - } - return scrollY; - } else { - for (int i = mReferencePosition - 1; i >= firstVisiblePosition; --i) { - if (mListViewItemHeights.get(i) == null) { - mListViewItemHeights.put(i, c.getMeasuredHeight()); - } - scrollY -= mListViewItemHeights.get(i); - } - return scrollY; - } - - } - return 0; - } - - public void clear() { - mPositions = null; - } - - // endregion -} diff --git a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/widgets/FloatingActionButton.java b/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/widgets/FloatingActionButton.java deleted file mode 100644 index bd008910..00000000 --- a/agendacalendarview/src/main/java/com/github/tibolte/agendacalendarview/widgets/FloatingActionButton.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.github.tibolte.agendacalendarview.widgets; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.ViewGroup; -import android.view.ViewTreeObserver; -import android.view.animation.AccelerateDecelerateInterpolator; -import android.view.animation.Interpolator; - -/** - * Floating action button helping to scroll back to the current date. - */ -public class FloatingActionButton extends com.google.android.material.floatingactionbutton.FloatingActionButton { - private static final int TRANSLATE_DURATION_MILLIS = 200; - - private boolean mVisible = true; - - private final Interpolator mInterpolator = new AccelerateDecelerateInterpolator(); - - // region Constructors - - public FloatingActionButton(Context context) { - super(context); - } - - public FloatingActionButton(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - // endregion - - // region Overrides - - @Override - public void show() { - show(true); - } - - @Override - public void hide() { - hide(true); - } - - // endregion - - // region Public methods - - public void show(boolean animate) { - toggle(true, animate, false); - } - - public void hide(boolean animate) { - toggle(false, animate, false); - } - - public boolean isVisible() { - return mVisible; - } - - // endregion - - // region Private methods - - private void toggle(final boolean visible, final boolean animate, boolean force) { - if (mVisible != visible || force) { - mVisible = visible; - int height = getHeight(); - if (height == 0 && !force) { - ViewTreeObserver vto = getViewTreeObserver(); - if (vto.isAlive()) { - vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - ViewTreeObserver currentVto = getViewTreeObserver(); - if (currentVto.isAlive()) { - currentVto.removeOnPreDrawListener(this); - } - toggle(visible, animate, true); - return true; - } - }); - return; - } - } - int translationY = visible ? 0 : height + getMarginBottom(); - if (animate) { - animate().setInterpolator(mInterpolator) - .setDuration(TRANSLATE_DURATION_MILLIS) - .translationY(translationY); - } else { - setTranslationY(translationY); - } - } - } - - private int getMarginBottom() { - int marginBottom = 0; - final ViewGroup.LayoutParams layoutParams = getLayoutParams(); - if (layoutParams instanceof ViewGroup.MarginLayoutParams) { - marginBottom = ((ViewGroup.MarginLayoutParams) layoutParams).bottomMargin; - } - return marginBottom; - } - - // endregion -} diff --git a/agendacalendarview/src/main/res/drawable/agenda_day_circle.xml b/agendacalendarview/src/main/res/drawable/agenda_day_circle.xml deleted file mode 100644 index e1398e00..00000000 --- a/agendacalendarview/src/main/res/drawable/agenda_day_circle.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/agendacalendarview/src/main/res/drawable/event_color_circle.xml b/agendacalendarview/src/main/res/drawable/event_color_circle.xml deleted file mode 100644 index 3cc72359..00000000 --- a/agendacalendarview/src/main/res/drawable/event_color_circle.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/agendacalendarview/src/main/res/drawable/fab_arrow.xml b/agendacalendarview/src/main/res/drawable/fab_arrow.xml deleted file mode 100644 index 3b4d3a8c..00000000 --- a/agendacalendarview/src/main/res/drawable/fab_arrow.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - \ No newline at end of file diff --git a/agendacalendarview/src/main/res/drawable/selected_day_color_circle.xml b/agendacalendarview/src/main/res/drawable/selected_day_color_circle.xml deleted file mode 100644 index 3d53cf8c..00000000 --- a/agendacalendarview/src/main/res/drawable/selected_day_color_circle.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/agendacalendarview/src/main/res/drawable/shadow.xml b/agendacalendarview/src/main/res/drawable/shadow.xml deleted file mode 100644 index 7ab76207..00000000 --- a/agendacalendarview/src/main/res/drawable/shadow.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/agendacalendarview/src/main/res/layout/list_item_week.xml b/agendacalendarview/src/main/res/layout/list_item_week.xml deleted file mode 100644 index 846ba637..00000000 --- a/agendacalendarview/src/main/res/layout/list_item_week.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/agendacalendarview/src/main/res/layout/view_agenda.xml b/agendacalendarview/src/main/res/layout/view_agenda.xml deleted file mode 100644 index 5f4a704e..00000000 --- a/agendacalendarview/src/main/res/layout/view_agenda.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/agendacalendarview/src/main/res/layout/view_agenda_event.xml b/agendacalendarview/src/main/res/layout/view_agenda_event.xml deleted file mode 100644 index 92329386..00000000 --- a/agendacalendarview/src/main/res/layout/view_agenda_event.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/agendacalendarview/src/main/res/layout/view_agenda_header.xml b/agendacalendarview/src/main/res/layout/view_agenda_header.xml deleted file mode 100644 index e0391dd5..00000000 --- a/agendacalendarview/src/main/res/layout/view_agenda_header.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/agendacalendarview/src/main/res/layout/view_agendacalendar.xml b/agendacalendarview/src/main/res/layout/view_agendacalendar.xml deleted file mode 100644 index e2df4255..00000000 --- a/agendacalendarview/src/main/res/layout/view_agendacalendar.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/agendacalendarview/src/main/res/layout/view_calendar.xml b/agendacalendarview/src/main/res/layout/view_calendar.xml deleted file mode 100644 index 4b3839e0..00000000 --- a/agendacalendarview/src/main/res/layout/view_calendar.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/agendacalendarview/src/main/res/layout/view_day_calendar_header.xml b/agendacalendarview/src/main/res/layout/view_day_calendar_header.xml deleted file mode 100644 index 2326af49..00000000 --- a/agendacalendarview/src/main/res/layout/view_day_calendar_header.xml +++ /dev/null @@ -1,9 +0,0 @@ - - \ No newline at end of file diff --git a/agendacalendarview/src/main/res/layout/view_day_cell.xml b/agendacalendarview/src/main/res/layout/view_day_cell.xml deleted file mode 100644 index cebb97db..00000000 --- a/agendacalendarview/src/main/res/layout/view_day_cell.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/agendacalendarview/src/main/res/values-en/strings.xml b/agendacalendarview/src/main/res/values-en/strings.xml deleted file mode 100644 index 1d9b1040..00000000 --- a/agendacalendarview/src/main/res/values-en/strings.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - Today - Tomorrow - d - All day - No events - - - LLLL - MMM - diff --git a/agendacalendarview/src/main/res/values/attrs.xml b/agendacalendarview/src/main/res/values/attrs.xml deleted file mode 100644 index 6750df84..00000000 --- a/agendacalendarview/src/main/res/values/attrs.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/agendacalendarview/src/main/res/values/colors.xml b/agendacalendarview/src/main/res/values/colors.xml deleted file mode 100644 index 7904509d..00000000 --- a/agendacalendarview/src/main/res/values/colors.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - #000000 - #9C9CA0 - #CCFFFFFF - #F3F3F3 - - - - #00000000 - - - #2196F3 - #1976D2 - #2196F3 - #BBDEFB - #4caf50 - #FFFFFF - - \ No newline at end of file diff --git a/agendacalendarview/src/main/res/values/dimens.xml b/agendacalendarview/src/main/res/values/dimens.xml deleted file mode 100644 index 7b639f8d..00000000 --- a/agendacalendarview/src/main/res/values/dimens.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - 20dp - 52dp - 14dp - 32dp - - - 60dp - - - - - 70dp - 5dp - 15dp - 5dp - \ No newline at end of file diff --git a/agendacalendarview/src/main/res/values/strings.xml b/agendacalendarview/src/main/res/values/strings.xml deleted file mode 100644 index 7c2c5f8a..00000000 --- a/agendacalendarview/src/main/res/values/strings.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - LLLL - E - - - Dziś - Jutro - d - Cały dzień - Brak wydarzeń - - MMM - diff --git a/agendacalendarview/src/main/res/values/styles.xml b/agendacalendarview/src/main/res/values/styles.xml deleted file mode 100644 index b4bf4679..00000000 --- a/agendacalendarview/src/main/res/values/styles.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/annotation/.gitignore b/annotation/.gitignore deleted file mode 100644 index 796b96d1..00000000 --- a/annotation/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/annotation/build.gradle b/annotation/build.gradle deleted file mode 100644 index ee7f6d51..00000000 --- a/annotation/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) Kuba Szczodrzyński 2020-3-28. - */ - -apply plugin: 'java-library' -apply plugin: 'kotlin' -apply plugin: 'kotlin-kapt' - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" -} - -sourceCompatibility = "7" -targetCompatibility = "7" - -repositories { - mavenCentral() -} -compileKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} -compileTestKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} diff --git a/annotation/src/main/java/pl/szczodrzynski/edziennik/annotation/SelectiveDao.kt b/annotation/src/main/java/pl/szczodrzynski/edziennik/annotation/SelectiveDao.kt deleted file mode 100644 index d37e5b0a..00000000 --- a/annotation/src/main/java/pl/szczodrzynski/edziennik/annotation/SelectiveDao.kt +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) Kuba Szczodrzyński 2020-3-28. - */ - -package pl.szczodrzynski.edziennik.annotation - -import kotlin.reflect.KClass - -@Target(AnnotationTarget.CLASS) -@Retention(AnnotationRetention.SOURCE) -@MustBeDocumented -annotation class SelectiveDao( - val db: KClass<*> -) diff --git a/annotation/src/main/java/pl/szczodrzynski/edziennik/annotation/UpdateSelective.kt b/annotation/src/main/java/pl/szczodrzynski/edziennik/annotation/UpdateSelective.kt deleted file mode 100644 index 224fca1c..00000000 --- a/annotation/src/main/java/pl/szczodrzynski/edziennik/annotation/UpdateSelective.kt +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) Kuba Szczodrzyński 2020-3-28. - */ - -package pl.szczodrzynski.edziennik.annotation - -@Target(AnnotationTarget.FUNCTION) -@Retention(AnnotationRetention.SOURCE) -@MustBeDocumented -annotation class UpdateSelective( - val primaryKeys: Array, - val skippedColumns: Array = [] -) diff --git a/app/build.gradle b/app/build.gradle index 880d6f0f..0e83e107 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,21 +1,21 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' -apply plugin: 'kotlin-android-extensions' apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.firebase.crashlytics' android { - signingConfigs { - } compileSdkVersion setup.compileSdk + defaultConfig { applicationId 'pl.szczodrzynski.edziennik' minSdkVersion setup.minSdk targetSdkVersion setup.targetSdk + versionCode release.versionCode versionName release.versionName - multiDexEnabled true + + multiDexEnabled = true externalNativeBuild { cmake { @@ -28,41 +28,35 @@ android { variant.outputs.all { if (variant.buildType.name == "release") { outputFileName = "Edziennik_" + defaultConfig.versionName + ".apk" - } else if (variant.buildType.name == "debugMinify") { - outputFileName = "Edziennik_" + defaultConfig.versionName + "_debugMinify.apk" } else { outputFileName = "Edziennik_" + defaultConfig.versionName + "_debug.apk" } } } debug { - minifyEnabled false + minifyEnabled = false } release { - minifyEnabled true - shrinkResources true - proguardFiles getDefaultProguardFile('proguard-android.txt') + minifyEnabled = true + shrinkResources = true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles fileTree('proguard').asList().toArray() } } - dependencies { - implementation "com.google.firebase:firebase-core:${versions.firebase}" - } defaultConfig { vectorDrawables.useSupportLibrary = true } lintOptions { - checkReleaseBuilds false + checkReleaseBuilds = false } buildFeatures { dataBinding = true + viewBinding = true } compileOptions { - coreLibraryDesugaringEnabled true - sourceCompatibility '1.8' - targetCompatibility '1.8' - } - productFlavors { + coreLibraryDesugaringEnabled = true + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = "1.8" @@ -76,145 +70,93 @@ android { version "3.10.2" } } - ndkVersion '21.3.6528147' } -/*task finalizeBundleDebug(type: Copy) { - from("debug/debug") - include "app.aab" - destinationDir file("debug/debug") - rename "app.aab", "Edziennik_debug.aab" -} - -// it finalizes :bundleRelease -task finalizeBundleRelease(type: Copy) { - from("release/release") - include "app.aab" - destinationDir file("release/release") - rename "app.aab", "Edziennik_${android.defaultConfig.versionCode}.aab" -}*/ -/* -// this adds the above two tasks -tasks.whenTaskAdded { task -> - if (task.name == "bundleDebug") { - task.finalizedBy finalizeBundleDebug - } else if (task.name == "bundleRelease") { - task.finalizedBy finalizeBundleRelease - } -}*/ - dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.1' + // Language cores + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.1.5" - kapt "androidx.room:room-compiler:${versions.room}" - debugImplementation "com.amitshekhar.android:debug-db:1.0.5" + // Android Jetpack + implementation "androidx.appcompat:appcompat:1.2.0" + implementation "androidx.cardview:cardview:1.0.0" + implementation "androidx.constraintlayout:constraintlayout:2.0.4" + implementation "androidx.core:core-ktx:1.3.2" + implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0" + implementation "androidx.navigation:navigation-fragment-ktx:2.3.4" + implementation "androidx.recyclerview:recyclerview:1.1.0" + implementation "androidx.room:room-runtime:2.2.6" + implementation "androidx.work:work-runtime-ktx:2.5.0" + kapt "androidx.room:room-compiler:2.2.6" - implementation "android.arch.navigation:navigation-fragment-ktx:${versions.navigationFragment}" - implementation "androidx.appcompat:appcompat:${versions.appcompat}" - implementation "androidx.cardview:cardview:${versions.cardView}" - implementation "androidx.constraintlayout:constraintlayout:${versions.constraintLayout}" - implementation "androidx.core:core-ktx:${versions.ktx}" - implementation "androidx.gridlayout:gridlayout:${versions.gridLayout}" - implementation "androidx.legacy:legacy-support-v4:${versions.legacy}" - implementation "androidx.lifecycle:lifecycle-livedata-ktx:${versions.lifecycle}" - implementation "androidx.recyclerview:recyclerview:${versions.recyclerView}" - implementation "androidx.room:room-runtime:${versions.room}" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}" + // Google design libs + implementation "com.google.android.material:material:1.3.0" + implementation "com.google.android:flexbox:2.0.1" - implementation "com.google.android.gms:play-services-wearable:${versions.play_services}" - implementation "com.google.android.material:material:${versions.material}" - implementation "com.google.firebase:firebase-messaging:${versions.firebasemessaging}" + // Play Services/Firebase + implementation "com.google.android.gms:play-services-wearable:17.0.0" + implementation "com.google.firebase:firebase-core:18.0.2" + implementation "com.google.firebase:firebase-crashlytics:17.4.0" + implementation("com.google.firebase:firebase-messaging") { version { strictly "20.1.3" } } - //implementation "com.github.kuba2k2.MaterialDrawer:library:e603091449" - implementation "com.mikepenz:crossfader:1.6.0" // do not update - implementation "com.mikepenz:iconics-core:${versions.iconics}" - implementation "com.mikepenz:iconics-views:${versions.iconics}" - implementation "com.mikepenz:community-material-typeface:${versions.font_cmd}@aar" - implementation "com.mikepenz:materialize:1.2.1" + // OkHttp, Retrofit, Gson, Jsoup + implementation("com.squareup.okhttp3:okhttp") { version { strictly "3.12.13" } } + implementation "com.squareup.retrofit2:retrofit:2.9.0" + implementation "com.squareup.retrofit2:converter-gson:2.9.0" + implementation "com.squareup.retrofit2:converter-scalars:2.9.0" + implementation 'com.google.code.gson:gson:2.8.6' + implementation "org.jsoup:jsoup:1.13.1" + implementation "pl.droidsonroids:jspoon:1.3.2" + implementation "pl.droidsonroids.retrofit2:converter-jspoon:1.3.2" - implementation "com.github.kuba2k2:NavLib:${versions.navlib}" + // Szkolny.eu libraries/forks + implementation "eu.szkolny:agendacalendarview:1799f8ef47" + implementation "eu.szkolny:cafebar:5bf0c618de" + implementation "eu.szkolny.fslogin:lib:2.0.0" + implementation "eu.szkolny:material-about-library:0534abf316" + implementation "eu.szkolny:mhttp:af4b62e6e9" + implementation "eu.szkolny:nachos:0e5dfcaceb" + implementation "eu.szkolny.selective-dao:annotation:27f8f3f194" + implementation "pl.szczodrzynski:navlib:0.7.2" + implementation "pl.szczodrzynski:numberslidingpicker:2921225f76" + implementation "pl.szczodrzynski:recyclertablayout:700f980584" + implementation "pl.szczodrzynski:tachyon:551943a6b5" + kapt "eu.szkolny.selective-dao:codegen:27f8f3f194" - implementation "com.afollestad.material-dialogs:commons:${versions.materialdialogs}" - implementation "com.afollestad.material-dialogs:core:${versions.materialdialogs}" + // Iconics & related + implementation "com.mikepenz:iconics-core:5.2.8" + implementation "com.mikepenz:iconics-views:5.2.8" + implementation "com.mikepenz:community-material-typeface:5.8.55.0-kotlin@aar" + implementation "eu.szkolny:szkolny-font:1dab7d64ed" - implementation "cat.ereza:customactivityoncrash:2.2.0" + // Other dependencies + implementation "cat.ereza:customactivityoncrash:2.3.0" + implementation "com.afollestad.material-dialogs:commons:0.9.6.0" + implementation "com.afollestad.material-dialogs:core:0.9.6.0" implementation "com.applandeo:material-calendar-view:1.5.0" - implementation 'com.google.firebase:firebase-crashlytics:17.3.1' implementation "com.daimajia.swipelayout:library:1.2.0@aar" - implementation "com.evernote:android-job:1.2.6" implementation "com.github.antonKozyriatskyi:CircularProgressIndicator:1.2.2" implementation "com.github.bassaer:chatmessageview:2.0.1" - implementation("com.github.ozodrukh:CircularReveal:2.0.1@aar") {transitive = true} - implementation "com.heinrichreimersoftware:material-intro:1.5.8" // do not update - implementation "com.jaredrummler:colorpicker:1.0.2" - implementation("com.squareup.okhttp3:okhttp") { - version { - strictly "3.12.13" - } - } - implementation "com.theartofdev.edmodo:android-image-cropper:2.8.0" // do not update - implementation "com.wdullaer:materialdatetimepicker:4.1.2" + implementation "com.github.ChuckerTeam.Chucker:library:3.0.1" + implementation "com.github.jetradarmobile:android-snowfall:1.2.0" + implementation "com.github.wulkanowy.uonet-request-signer:hebe-jvm:a99ca50a31" + implementation("com.heinrichreimersoftware:material-intro") { version { strictly "1.5.8" } } + implementation "com.hypertrack:hyperlog:0.0.10" + implementation "com.jaredrummler:colorpicker:1.1.0" + implementation "com.qifan.powerpermission:powerpermission-coroutines:1.3.0" + implementation "com.qifan.powerpermission:powerpermission:1.3.0" + implementation "com.theartofdev.edmodo:android-image-cropper:2.8.0" + implementation "com.wdullaer:materialdatetimepicker:4.2.3" implementation "com.yuyh.json:jsonviewer:1.0.6" + implementation "io.coil-kt:coil:1.1.1" implementation "me.dm7.barcodescanner:zxing:1.9.8" implementation "me.grantland:autofittextview:0.2.1" implementation "me.leolin:ShortcutBadger:1.1.22@aar" - implementation "org.greenrobot:eventbus:3.1.1" - implementation "org.jsoup:jsoup:1.12.1" - implementation "pl.droidsonroids.gif:android-gif-drawable:1.2.15" - //implementation "se.emilsjolander:stickylistheaders:2.7.0" - implementation 'com.github.edisonw:StickyListHeaders:master-SNAPSHOT@aar' - implementation "uk.co.samuelwall:material-tap-target-prompt:2.14.0" + implementation "org.greenrobot:eventbus:3.2.0" + implementation("pl.droidsonroids.gif:android-gif-drawable") { version { strictly "1.2.15" } } - implementation project(":agendacalendarview") - implementation project(":cafebar") - implementation project(":material-about-library") - implementation project(":mhttp") - implementation project(":nachos") - //implementation project(":Navigation") - implementation project(":szkolny-font") - - implementation "com.github.ChuckerTeam.Chucker:library:3.0.1" - //releaseImplementation "com.github.ChuckerTeam.Chucker:library-no-op:3.0.1" - - //implementation 'com.github.wulkanowy:uonet-request-signer:master-SNAPSHOT' - //implementation 'com.github.kuba2k2.uonet-request-signer:android:master-63f094b14a-1' - - //implementation "org.redundent:kotlin-xml-builder:1.5.3" - - implementation 'com.github.wulkanowy.uonet-request-signer:hebe-jvm:a99ca50a31' - - implementation "androidx.work:work-runtime-ktx:${versions.work}" - - implementation 'com.hypertrack:hyperlog:0.0.10' - - implementation 'com.github.kuba2k2:RecyclerTabLayout:700f980584' - - implementation 'com.github.kuba2k2:Tachyon:551943a6b5' - - implementation "com.squareup.retrofit2:retrofit:${versions.retrofit}" - implementation "com.squareup.retrofit2:converter-gson:${versions.retrofit}" - - implementation 'com.github.jetradarmobile:android-snowfall:1.2.0' - - implementation "io.coil-kt:coil:0.9.2" - - implementation 'com.github.kuba2k2:NumberSlidingPicker:2921225f76' - - implementation project(":annotation") - kapt project(":codegen") - - implementation 'com.google.android:flexbox:2.0.1' - - implementation 'com.qifan.powerpermission:powerpermission:1.3.0' - implementation 'com.qifan.powerpermission:powerpermission-coroutines:1.3.0' - - implementation 'com.github.kuba2k2.FSLogin:lib:2.0.0' - implementation 'pl.droidsonroids:jspoon:1.3.2' - implementation "com.squareup.retrofit2:converter-scalars:2.8.1" - implementation "pl.droidsonroids.retrofit2:converter-jspoon:1.3.2" -} -repositories { - mavenCentral() + // Debug-only dependencies + debugImplementation "com.amitshekhar.android:debug-db:1.0.5" } diff --git a/app/proguard/app.pro b/app/proguard-rules.pro similarity index 100% rename from app/proguard/app.pro rename to app/proguard-rules.pro diff --git a/app/proguard/android-job.pro b/app/proguard/android-job.pro deleted file mode 100644 index 3f1a67be..00000000 --- a/app/proguard/android-job.pro +++ /dev/null @@ -1,14 +0,0 @@ --dontwarn com.evernote.android.job.gcm.** --dontwarn com.evernote.android.job.GcmAvailableHelper --dontwarn com.evernote.android.job.work.** --dontwarn com.evernote.android.job.WorkManagerAvailableHelper - --keep public class com.evernote.android.job.v21.PlatformJobService --keep public class com.evernote.android.job.v14.PlatformAlarmService --keep public class com.evernote.android.job.v14.PlatformAlarmReceiver --keep public class com.evernote.android.job.JobBootReceiver --keep public class com.evernote.android.job.JobRescheduleService --keep public class com.evernote.android.job.gcm.PlatformGcmService --keep public class com.evernote.android.job.work.PlatformWorker - --keep class com.evernote.android.job.** { *; } \ No newline at end of file diff --git a/app/proguard/blurry.pro b/app/proguard/blurry.pro deleted file mode 100644 index 980f404e..00000000 --- a/app/proguard/blurry.pro +++ /dev/null @@ -1 +0,0 @@ --keep class android.support.v8.renderscript.** { *; } \ No newline at end of file diff --git a/app/proguard/cafebar.pro b/app/proguard/cafebar.pro deleted file mode 100644 index 6f8147fd..00000000 --- a/app/proguard/cafebar.pro +++ /dev/null @@ -1,25 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in D:\AndroidSDK/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - --keep class !android.support.v7.internal.view.menu.**,android.support.** {*;} --keep class android.support.v7.graphics.** { *; } --dontwarn android.support.v7.graphics.** - --keep class android.support.design.widget.** { *; } --keep interface android.support.design.widget.** { *; } --dontwarn android.support.design.** diff --git a/app/proguard/iconics.pro b/app/proguard/iconics.pro deleted file mode 100644 index 0aa62122..00000000 --- a/app/proguard/iconics.pro +++ /dev/null @@ -1,14 +0,0 @@ -# Android iconics library - https://github.com/mikepenz/Android-Iconics -# Warning: works ONLY with iconics > 1.0.0 -# -# Tested on gradle config: -# -# compile 'com.mikepenz:iconics-core:1.7.1@aar' -# - --keep class com.mikepenz.iconics.** { *; } --keep class com.mikepenz.community_material_typeface_library.CommunityMaterial --keep class com.mikepenz.fontawesome_typeface_library.FontAwesome --keep class com.mikepenz.google_material_typeface_library.GoogleMaterial --keep class com.mikepenz.meteocons_typeface_library.Meteoconcs --keep class com.mikepenz.octicons_typeface_library.Octicons \ No newline at end of file diff --git a/app/proguard/mhttp.pro b/app/proguard/mhttp.pro deleted file mode 100644 index 6d3e4e38..00000000 --- a/app/proguard/mhttp.pro +++ /dev/null @@ -1,48 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/wangchao/Work/android-sdk/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} --dontwarn im.wangchao.** --dontwarn okio.** --dontwarn javax.annotation.Nullable --dontwarn javax.annotation.ParametersAreNonnullByDefault --keep class im.wangchao.** { *; } --keep class **_HttpBinder { *; } --keepclasseswithmembernames class * { - @im.wangchao.* ; -} --keepclasseswithmembernames class * { - @im.wangchao.* ; -} --keepclassmembers class * implements java.io.Serializable { - static final long serialVersionUID; - private static final java.io.ObjectStreamField[] serialPersistentFields; - !static !transient ; - private void writeObject(java.io.ObjectOutputStream); - private void readObject(java.io.ObjectInputStream); - java.lang.Object writeReplace(); - java.lang.Object readResolve(); -} -# okhttp --dontwarn okhttp3.** --dontwarn okio.** --dontwarn javax.annotation.** --dontwarn org.conscrypt.** -# A resource is loaded with a relative path so the package of this class must be preserved. --keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase - -# If you do not use Rx: --dontwarn rx.** \ No newline at end of file diff --git a/app/proguard/szkolny-font.pro b/app/proguard/szkolny-font.pro deleted file mode 100644 index 4e48be73..00000000 --- a/app/proguard/szkolny-font.pro +++ /dev/null @@ -1 +0,0 @@ --keep class com.mikepenz.szkolny_font_typeface_library.SzkolnyFont { *; } diff --git a/app/proguard/wear.pro b/app/proguard/wear.pro deleted file mode 100644 index f1b42451..00000000 --- a/app/proguard/wear.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/App.kt b/app/src/main/java/pl/szczodrzynski/edziennik/App.kt index 88bdc603..0bc6f2e0 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/App.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/App.kt @@ -26,7 +26,6 @@ import com.google.firebase.messaging.FirebaseMessaging import com.google.gson.Gson import com.hypertrack.hyperlog.HyperLog import com.mikepenz.iconics.Iconics -import com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont import im.wangchao.mhttp.MHttp import kotlinx.coroutines.* import me.leolin.shortcutbadger.ShortcutBadger @@ -159,7 +158,6 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope { .errorActivity(CrashActivity::class.java) .apply() Iconics.init(applicationContext) - Iconics.registerFont(SzkolnyFont) App.db = AppDb(this) Themes.themeInt = config.ui.theme devMode = config.debugMode diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt index 1e73e267..de9b5f85 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt @@ -23,16 +23,16 @@ import androidx.lifecycle.Observer import androidx.navigation.NavOptions import com.danimahardhika.cafebar.CafeBar import com.google.android.material.dialog.MaterialAlertDialogBuilder -import com.mikepenz.iconics.IconicsColor import com.mikepenz.iconics.IconicsDrawable -import com.mikepenz.iconics.IconicsSize import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial -import com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont +import com.mikepenz.iconics.utils.colorInt +import com.mikepenz.iconics.utils.sizeDp import com.mikepenz.materialdrawer.model.DividerDrawerItem import com.mikepenz.materialdrawer.model.ProfileDrawerItem import com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem import com.mikepenz.materialdrawer.model.interfaces.* import com.mikepenz.materialdrawer.model.utils.withIsHiddenInMiniDrawer +import eu.szkolny.font.SzkolnyFont import kotlinx.coroutines.* import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe @@ -152,7 +152,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope { .withPopToHome(false) list += NavTarget(DRAWER_ITEM_TIMETABLE, R.string.menu_timetable, TimetableFragment::class) - .withIcon(CommunityMaterial.Icon2.cmd_timetable) + .withIcon(CommunityMaterial.Icon3.cmd_timetable) .withBadgeTypeId(TYPE_LESSON_CHANGE) .isInDrawer(true) @@ -162,7 +162,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope { .isInDrawer(true) list += NavTarget(DRAWER_ITEM_GRADES, R.string.menu_grades, GradesListFragment::class) - .withIcon(CommunityMaterial.Icon2.cmd_numeric_5_box_outline) + .withIcon(CommunityMaterial.Icon3.cmd_numeric_5_box_outline) .withBadgeTypeId(TYPE_GRADE) .isInDrawer(true) @@ -200,7 +200,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope { .isBelowSeparator(true) list += NavTarget(DRAWER_ITEM_SETTINGS, R.string.menu_settings, SettingsNewFragment::class) - .withIcon(CommunityMaterial.Icon2.cmd_settings_outline) + .withIcon(CommunityMaterial.Icon.cmd_cog_outline) .isInDrawer(true) .isStatic(true) .isBelowSeparator(true) @@ -208,7 +208,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope { // profile settings items list += NavTarget(DRAWER_PROFILE_ADD_NEW, R.string.menu_add_new_profile, null) - .withIcon(CommunityMaterial.Icon2.cmd_plus) + .withIcon(CommunityMaterial.Icon3.cmd_plus) .withDescription(R.string.drawer_add_new_profile_desc) .isInProfileList(true) @@ -237,7 +237,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope { if (App.devMode) { list += NavTarget(DRAWER_ITEM_DEBUG, R.string.menu_debug, DebugFragment::class) list += NavTarget(TARGET_LAB, R.string.menu_lab, LabFragment::class) - .withIcon(CommunityMaterial.Icon.cmd_flask_outline) + .withIcon(CommunityMaterial.Icon2.cmd_flask_outline) .isInDrawer(true) .isBelowSeparator(true) .isStatic(true) @@ -519,7 +519,11 @@ class MainActivity : AppCompatActivity(), CoroutineScope { navView.coordinator.postDelayed({ CafeBar.builder(this) .content(R.string.rate_snackbar_text) - .icon(IconicsDrawable(this).icon(CommunityMaterial.Icon2.cmd_star_outline).size(IconicsSize.dp(20)).color(IconicsColor.colorInt(Themes.getPrimaryTextColor(this)))) + .icon(IconicsDrawable(this).apply { + icon = CommunityMaterial.Icon3.cmd_star_outline + sizeDp = 20 + colorInt = Themes.getPrimaryTextColor(this@MainActivity) + }) .positiveText(R.string.rate_snackbar_positive) .positiveColor(-0xb350b0) .negativeText(R.string.rate_snackbar_negative) @@ -532,12 +536,12 @@ class MainActivity : AppCompatActivity(), CoroutineScope { app.config.appRateSnackbarTime = 0 } .onNegative { cafeBar -> - Toast.makeText(this, "Szkoda, opinie innych pomagają mi rozwijać aplikację.", Toast.LENGTH_LONG).show() + Toast.makeText(this, R.string.rate_snackbar_negative_message, Toast.LENGTH_LONG).show() cafeBar.dismiss() app.config.appRateSnackbarTime = 0 } .onNeutral { cafeBar -> - Toast.makeText(this, "OK", Toast.LENGTH_LONG).show() + Toast.makeText(this, R.string.ok, Toast.LENGTH_LONG).show() cafeBar.dismiss() app.config.appRateSnackbarTime = System.currentTimeMillis() + 7 * 24 * 60 * 60 * 1000 } @@ -561,7 +565,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope { BottomSheetSeparatorItem(false), BottomSheetPrimaryItem(false) .withTitle(R.string.menu_settings) - .withIcon(CommunityMaterial.Icon2.cmd_settings_outline) + .withIcon(CommunityMaterial.Icon.cmd_cog_outline) .withOnClickListener(View.OnClickListener { loadTarget(DRAWER_ITEM_SETTINGS) }), BottomSheetPrimaryItem(false) .withTitle(R.string.menu_feedback) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/AnnouncementDao.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/AnnouncementDao.kt index 67e034c5..88b3ccd1 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/AnnouncementDao.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/AnnouncementDao.kt @@ -8,9 +8,9 @@ import androidx.room.Dao import androidx.room.Query import androidx.room.RawQuery import androidx.sqlite.db.SupportSQLiteQuery +import eu.szkolny.selectivedao.annotation.SelectiveDao +import eu.szkolny.selectivedao.annotation.UpdateSelective import pl.szczodrzynski.edziennik.App -import pl.szczodrzynski.edziennik.annotation.SelectiveDao -import pl.szczodrzynski.edziennik.annotation.UpdateSelective import pl.szczodrzynski.edziennik.data.db.AppDb import pl.szczodrzynski.edziennik.data.db.entity.Announcement import pl.szczodrzynski.edziennik.data.db.entity.Metadata diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/AttendanceDao.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/AttendanceDao.kt index 97513689..3ffdc1b8 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/AttendanceDao.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/AttendanceDao.kt @@ -8,9 +8,9 @@ import androidx.room.Dao import androidx.room.Query import androidx.room.RawQuery import androidx.sqlite.db.SupportSQLiteQuery +import eu.szkolny.selectivedao.annotation.SelectiveDao +import eu.szkolny.selectivedao.annotation.UpdateSelective import pl.szczodrzynski.edziennik.App -import pl.szczodrzynski.edziennik.annotation.SelectiveDao -import pl.szczodrzynski.edziennik.annotation.UpdateSelective import pl.szczodrzynski.edziennik.data.db.AppDb import pl.szczodrzynski.edziennik.data.db.entity.Attendance import pl.szczodrzynski.edziennik.data.db.entity.Metadata diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/EventDao.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/EventDao.kt index a532602b..897d53ff 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/EventDao.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/EventDao.kt @@ -10,9 +10,9 @@ import androidx.room.RawQuery import androidx.room.Transaction import androidx.sqlite.db.SimpleSQLiteQuery import androidx.sqlite.db.SupportSQLiteQuery +import eu.szkolny.selectivedao.annotation.SelectiveDao +import eu.szkolny.selectivedao.annotation.UpdateSelective import pl.szczodrzynski.edziennik.App -import pl.szczodrzynski.edziennik.annotation.SelectiveDao -import pl.szczodrzynski.edziennik.annotation.UpdateSelective import pl.szczodrzynski.edziennik.data.db.AppDb import pl.szczodrzynski.edziennik.data.db.entity.Event import pl.szczodrzynski.edziennik.data.db.entity.Metadata diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/GradeDao.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/GradeDao.kt index 4fcfc721..6254f80b 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/GradeDao.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/GradeDao.kt @@ -9,9 +9,9 @@ import androidx.room.Query import androidx.room.RawQuery import androidx.room.Transaction import androidx.sqlite.db.SupportSQLiteQuery +import eu.szkolny.selectivedao.annotation.SelectiveDao +import eu.szkolny.selectivedao.annotation.UpdateSelective import pl.szczodrzynski.edziennik.App -import pl.szczodrzynski.edziennik.annotation.SelectiveDao -import pl.szczodrzynski.edziennik.annotation.UpdateSelective import pl.szczodrzynski.edziennik.data.db.AppDb import pl.szczodrzynski.edziennik.data.db.entity.Grade import pl.szczodrzynski.edziennik.data.db.entity.Metadata diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/LuckyNumberDao.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/LuckyNumberDao.kt index ad44c0d3..3c752124 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/LuckyNumberDao.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/LuckyNumberDao.kt @@ -8,9 +8,9 @@ import androidx.room.Dao import androidx.room.Query import androidx.room.RawQuery import androidx.sqlite.db.SupportSQLiteQuery +import eu.szkolny.selectivedao.annotation.SelectiveDao +import eu.szkolny.selectivedao.annotation.UpdateSelective import pl.szczodrzynski.edziennik.App -import pl.szczodrzynski.edziennik.annotation.SelectiveDao -import pl.szczodrzynski.edziennik.annotation.UpdateSelective import pl.szczodrzynski.edziennik.data.db.AppDb import pl.szczodrzynski.edziennik.data.db.entity.LuckyNumber import pl.szczodrzynski.edziennik.data.db.entity.Metadata diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/MessageDao.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/MessageDao.kt index a0be36ab..51d56854 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/MessageDao.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/MessageDao.kt @@ -8,9 +8,9 @@ import androidx.room.Dao import androidx.room.Query import androidx.room.RawQuery import androidx.sqlite.db.SupportSQLiteQuery +import eu.szkolny.selectivedao.annotation.SelectiveDao +import eu.szkolny.selectivedao.annotation.UpdateSelective import pl.szczodrzynski.edziennik.App -import pl.szczodrzynski.edziennik.annotation.SelectiveDao -import pl.szczodrzynski.edziennik.annotation.UpdateSelective import pl.szczodrzynski.edziennik.data.db.AppDb import pl.szczodrzynski.edziennik.data.db.entity.Message import pl.szczodrzynski.edziennik.data.db.entity.Metadata diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/NoticeDao.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/NoticeDao.kt index 79bae175..51f3e839 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/NoticeDao.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/NoticeDao.kt @@ -8,9 +8,9 @@ import androidx.room.Dao import androidx.room.Query import androidx.room.RawQuery import androidx.sqlite.db.SupportSQLiteQuery +import eu.szkolny.selectivedao.annotation.SelectiveDao +import eu.szkolny.selectivedao.annotation.UpdateSelective import pl.szczodrzynski.edziennik.App -import pl.szczodrzynski.edziennik.annotation.SelectiveDao -import pl.szczodrzynski.edziennik.annotation.UpdateSelective import pl.szczodrzynski.edziennik.data.db.AppDb import pl.szczodrzynski.edziennik.data.db.entity.Metadata import pl.szczodrzynski.edziennik.data.db.entity.Notice diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/TeacherAbsenceDao.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/TeacherAbsenceDao.kt index 1528adf1..f12248b8 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/TeacherAbsenceDao.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/TeacherAbsenceDao.kt @@ -8,9 +8,9 @@ import androidx.room.Dao import androidx.room.Query import androidx.room.RawQuery import androidx.sqlite.db.SupportSQLiteQuery +import eu.szkolny.selectivedao.annotation.SelectiveDao +import eu.szkolny.selectivedao.annotation.UpdateSelective import pl.szczodrzynski.edziennik.App -import pl.szczodrzynski.edziennik.annotation.SelectiveDao -import pl.szczodrzynski.edziennik.annotation.UpdateSelective import pl.szczodrzynski.edziennik.data.db.AppDb import pl.szczodrzynski.edziennik.data.db.entity.Metadata import pl.szczodrzynski.edziennik.data.db.entity.TeacherAbsence diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/TimetableDao.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/TimetableDao.kt index cc236dc6..c7cbee12 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/TimetableDao.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/TimetableDao.kt @@ -8,9 +8,9 @@ import androidx.room.Dao import androidx.room.Query import androidx.room.RawQuery import androidx.sqlite.db.SupportSQLiteQuery +import eu.szkolny.selectivedao.annotation.SelectiveDao +import eu.szkolny.selectivedao.annotation.UpdateSelective import pl.szczodrzynski.edziennik.App -import pl.szczodrzynski.edziennik.annotation.SelectiveDao -import pl.szczodrzynski.edziennik.annotation.UpdateSelective import pl.szczodrzynski.edziennik.data.db.AppDb import pl.szczodrzynski.edziennik.data.db.entity.Lesson import pl.szczodrzynski.edziennik.data.db.entity.Metadata diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/RegisterUnavailableDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/RegisterUnavailableDialog.kt index 6ecd494f..b9e733b8 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/RegisterUnavailableDialog.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/RegisterUnavailableDialog.kt @@ -8,7 +8,7 @@ import android.text.method.LinkMovementMethod import android.view.LayoutInflater import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity -import coil.api.load +import coil.load import com.google.android.material.dialog.MaterialAlertDialogBuilder import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/day/DayDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/day/DayDialog.kt index c6a7b2f9..e5b7768d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/day/DayDialog.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/day/DayDialog.kt @@ -10,8 +10,6 @@ import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.dialog.MaterialAlertDialogBuilder -import kotlinx.android.synthetic.main.row_lesson_change_item.view.* -import kotlinx.android.synthetic.main.row_teacher_absence_item.view.* import kotlinx.coroutines.* import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.data.db.entity.Lesson @@ -111,7 +109,7 @@ class DayDialog( } lessonChanges.ifNotEmpty { - b.lessonChangeContainer.visibility = View.VISIBLE + b.lessonChangeContainer.root.visibility = View.VISIBLE b.lessonChangeContainer.lessonChangeCount.text = it.size.toString() b.lessonChangeLayout.onClick { @@ -130,7 +128,7 @@ class DayDialog( } teacherAbsences.ifNotEmpty { - b.teacherAbsenceContainer.visibility = View.VISIBLE + b.teacherAbsenceContainer.root.visibility = View.VISIBLE b.teacherAbsenceContainer.teacherAbsenceCount.text = it.size.toString() b.teacherAbsenceLayout.onClick { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventManualDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventManualDialog.kt index 06b5f1a6..7240934b 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventManualDialog.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventManualDialog.kt @@ -378,7 +378,7 @@ class EventManualDialog( customColor = color } }) - colorPickerDialog.show(activity.fragmentManager, "color-picker-dialog") + colorPickerDialog.show(activity.supportFragmentManager, "color-picker-dialog") } }} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.kt index ec212cea..367b00da 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.kt @@ -16,12 +16,11 @@ import com.github.tibolte.agendacalendarview.CalendarPickerController import com.github.tibolte.agendacalendarview.models.BaseCalendarEvent import com.github.tibolte.agendacalendarview.models.CalendarEvent import com.github.tibolte.agendacalendarview.models.IDayItem -import com.mikepenz.iconics.IconicsColor import com.mikepenz.iconics.IconicsDrawable -import com.mikepenz.iconics.IconicsSize import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial -import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial.Icon2 -import com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont +import com.mikepenz.iconics.utils.colorInt +import com.mikepenz.iconics.utils.sizeDp +import eu.szkolny.font.SzkolnyFont import kotlinx.coroutines.* import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.MainActivity @@ -89,7 +88,7 @@ class AgendaFragment : Fragment(), CoroutineScope { }), BottomSheetPrimaryItem(true) .withTitle(R.string.menu_agenda_change_view) - .withIcon(if (type == Profile.AGENDA_DEFAULT) CommunityMaterial.Icon.cmd_calendar_outline else CommunityMaterial.Icon.cmd_format_list_bulleted_square) + .withIcon(if (type == Profile.AGENDA_DEFAULT) CommunityMaterial.Icon.cmd_calendar_outline else CommunityMaterial.Icon2.cmd_format_list_bulleted_square) .withOnClickListener(View.OnClickListener { activity.bottomSheet.close() type = if (type == Profile.AGENDA_DEFAULT) Profile.AGENDA_CALENDAR else Profile.AGENDA_DEFAULT @@ -111,7 +110,7 @@ class AgendaFragment : Fragment(), CoroutineScope { activity.navView.bottomBar.fabEnable = true activity.navView.bottomBar.fabExtendedText = getString(R.string.add) - activity.navView.bottomBar.fabIcon = Icon2.cmd_plus + activity.navView.bottomBar.fabIcon = CommunityMaterial.Icon3.cmd_plus activity.navView.setFabOnClickListener(View.OnClickListener { EventManualDialog(activity, app.profileId, defaultDate = actualDate) }) @@ -278,10 +277,11 @@ class AgendaFragment : Fragment(), CoroutineScope { val unreadEventDates = mutableSetOf() events.forEach { event -> - val eventIcon = IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_checkbox_blank_circle) - .size(IconicsSize.dp(10)) - .color(IconicsColor.colorInt(event.eventColor)) + val eventIcon = IconicsDrawable(activity).apply { + icon = CommunityMaterial.Icon.cmd_checkbox_blank_circle + sizeDp = 10 + colorInt = event.eventColor + } dayList.add(EventDay(event.startTimeCalendar, eventIcon)) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceFragment.kt index 0af177f9..194f36d2 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceFragment.kt @@ -60,7 +60,7 @@ class AttendanceFragment : Fragment(), CoroutineScope { activity.bottomSheet.prependItems( BottomSheetPrimaryItem(true) .withTitle(R.string.menu_attendance_config) - .withIcon(CommunityMaterial.Icon2.cmd_settings_outline) + .withIcon(CommunityMaterial.Icon.cmd_cog_outline) .withOnClickListener(View.OnClickListener { activity.bottomSheet.close() AttendanceConfigDialog(activity, true, null, null) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/behaviour/NoticesAdapter.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/behaviour/NoticesAdapter.kt index f495d61e..a3288da2 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/behaviour/NoticesAdapter.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/behaviour/NoticesAdapter.kt @@ -13,9 +13,9 @@ import androidx.cardview.widget.CardView import androidx.recyclerview.widget.RecyclerView import com.mikepenz.iconics.IconicsDrawable import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial -import com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont import com.mikepenz.iconics.utils.colorRes import com.mikepenz.iconics.utils.sizeDp +import eu.szkolny.font.SzkolnyFont import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.data.api.LOGIN_TYPE_MOBIDZIENNIK @@ -49,17 +49,26 @@ class NoticesAdapter//getting the context and product list with constructor holder.noticesItemAddedDate.text = Date.fromMillis(notice.addedDate).formattedString if (notice.type == Notice.TYPE_POSITIVE) { - holder.noticesItemType.setImageDrawable(IconicsDrawable(context, CommunityMaterial.Icon2.cmd_plus_circle_outline) - .colorRes(R.color.md_green_600) - .sizeDp(36)) + holder.noticesItemType.setImageDrawable( + IconicsDrawable(context, CommunityMaterial.Icon3.cmd_plus_circle_outline).apply { + colorRes = R.color.md_green_600 + sizeDp = 36 + } + ) } else if (notice.type == Notice.TYPE_NEGATIVE) { - holder.noticesItemType.setImageDrawable(IconicsDrawable(context, CommunityMaterial.Icon.cmd_alert_decagram_outline) - .colorRes(R.color.md_red_600) - .sizeDp(36)) + holder.noticesItemType.setImageDrawable( + IconicsDrawable(context, CommunityMaterial.Icon.cmd_alert_decagram_outline).apply { + colorRes = R.color.md_red_600 + sizeDp = 36 + } + ) } else { - holder.noticesItemType.setImageDrawable(IconicsDrawable(context, SzkolnyFont.Icon.szf_message_processing_outline) - .colorRes(R.color.md_blue_500) - .sizeDp(36)) + holder.noticesItemType.setImageDrawable( + IconicsDrawable(context, SzkolnyFont.Icon.szf_message_processing_outline).apply { + colorRes = R.color.md_blue_500 + sizeDp = 36 + } + ) } if (!notice.seen) { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/feedback/FeedbackFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/feedback/FeedbackFragment.kt index 63f7500f..3c33be8d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/feedback/FeedbackFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/feedback/FeedbackFragment.kt @@ -14,8 +14,8 @@ import android.widget.PopupMenu import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment -import coil.Coil -import coil.api.load +import coil.imageLoader +import coil.request.ImageRequest import com.github.bassaer.chatmessageview.model.IChatUser import com.github.bassaer.chatmessageview.model.Message import com.github.bassaer.chatmessageview.view.ChatView @@ -34,14 +34,6 @@ import pl.szczodrzynski.edziennik.onClick import pl.szczodrzynski.edziennik.utils.Utils import pl.szczodrzynski.edziennik.utils.Utils.openUrl import java.util.* -import kotlin.collections.List -import kotlin.collections.any -import kotlin.collections.filter -import kotlin.collections.firstOrNull -import kotlin.collections.forEach -import kotlin.collections.forEachIndexed -import kotlin.collections.isNotEmpty -import kotlin.collections.mutableMapOf import kotlin.collections.set import kotlin.coroutines.CoroutineContext @@ -221,13 +213,15 @@ class FeedbackFragment : Fragment(), CoroutineScope { Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888).also { bmp -> launch { Log.d(TAG, "Created image for $userName") - Coil.load(activity, image) { - target { + val request = ImageRequest.Builder(activity) + .data(image) + .target { val canvas = Canvas(bmp) it.setBounds(0, 0, bmp.width, bmp.height) it.draw(canvas) } - } + .build() + activity.imageLoader.enqueue(request) } } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesListFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesListFragment.kt index 33d69c60..eb7fdcb1 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesListFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesListFragment.kt @@ -15,7 +15,6 @@ import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial -import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial.Icon2 import kotlinx.coroutines.* import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.MainActivity.Companion.TARGET_GRADES_EDITOR @@ -71,7 +70,7 @@ class GradesListFragment : Fragment(), CoroutineScope { val adapter = GradesAdapter(activity) var firstRun = true - app.db.gradeDao().getAllOrderBy(App.profileId, app.gradesManager.getOrderByString()).observe(this@GradesListFragment, Observer { grades -> this@GradesListFragment.launch { + app.db.gradeDao().getAllOrderBy(App.profileId, app.gradesManager.getOrderByString()).observe(viewLifecycleOwner, Observer { grades -> this@GradesListFragment.launch { if (!isAdded) return@launch val items = when { @@ -135,7 +134,7 @@ class GradesListFragment : Fragment(), CoroutineScope { activity.bottomSheet.prependItems( BottomSheetPrimaryItem(true) .withTitle(R.string.menu_grades_config) - .withIcon(Icon2.cmd_settings_outline) + .withIcon(CommunityMaterial.Icon.cmd_cog_outline) .withOnClickListener(View.OnClickListener { activity.bottomSheet.close() GradesConfigDialog(activity, true, null, null) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CounterActivity.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CounterActivity.kt index e337f720..868b330f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CounterActivity.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CounterActivity.kt @@ -7,9 +7,9 @@ package pl.szczodrzynski.edziennik.ui.modules.home import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import com.mikepenz.iconics.IconicsDrawable -import com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont import com.mikepenz.iconics.utils.colorInt import com.mikepenz.iconics.utils.sizeDp +import eu.szkolny.font.SzkolnyFont import kotlinx.coroutines.* import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.data.db.entity.Lesson @@ -59,9 +59,12 @@ class CounterActivity : AppCompatActivity(), CoroutineScope { } } - b.bellSync.setImageDrawable(IconicsDrawable(this@CounterActivity, SzkolnyFont.Icon.szf_alarm_bell_outline) - .colorInt(0xff404040.toInt()) - .sizeDp(36)) + b.bellSync.setImageDrawable( + IconicsDrawable(this@CounterActivity, SzkolnyFont.Icon.szf_alarm_bell_outline).apply { + colorInt = 0xff404040.toInt() + sizeDp = 36 + } + ) b.bellSync.onClick { BellSyncTimeChooseDialog(activity = this@CounterActivity) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt index 8afd7c04..944c60e8 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt @@ -19,14 +19,13 @@ import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial.Icon -import com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont +import eu.szkolny.font.SzkolnyFont import kotlinx.coroutines.* import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.data.db.entity.LoginStore import pl.szczodrzynski.edziennik.databinding.FragmentHomeBinding import pl.szczodrzynski.edziennik.ui.dialogs.home.StudentNumberDialog import pl.szczodrzynski.edziennik.ui.modules.home.cards.* -import pl.szczodrzynski.edziennik.utils.Themes import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetSeparatorItem import kotlin.coroutines.CoroutineContext @@ -75,7 +74,7 @@ class HomeFragment : Fragment(), CoroutineScope { private lateinit var activity: MainActivity private lateinit var b: FragmentHomeBinding - private lateinit var job: Job + private val job: Job = Job() override val coroutineContext: CoroutineContext get() = job + Dispatchers.Main @@ -83,10 +82,8 @@ class HomeFragment : Fragment(), CoroutineScope { activity = (getActivity() as MainActivity?) ?: return null context ?: return null app = activity.application as App - context!!.theme.applyStyle(Themes.appTheme, true) b = FragmentHomeBinding.inflate(inflater) b.refreshLayout.setParent(activity.swipeRefreshLayout) - job = Job() return b.root } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeAvailabilityCard.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeAvailabilityCard.kt index 957dff0c..fd54748e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeAvailabilityCard.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeAvailabilityCard.kt @@ -12,7 +12,7 @@ import androidx.core.text.HtmlCompat import androidx.core.view.isVisible import androidx.core.view.plusAssign import androidx.core.view.setMargins -import coil.api.load +import coil.load import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt index 68363ec6..a2e4f9d7 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt @@ -15,8 +15,8 @@ import androidx.core.view.setMargins import androidx.lifecycle.Observer import com.mikepenz.iconics.IconicsDrawable import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial -import com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont import com.mikepenz.iconics.utils.sizeDp +import eu.szkolny.font.SzkolnyFont import kotlinx.coroutines.* import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe @@ -87,17 +87,26 @@ class HomeTimetableCard( } holder.root += b.root - b.settings.setImageDrawable(IconicsDrawable(activity, CommunityMaterial.Icon2.cmd_settings_outline) - .colorAttr(activity, R.attr.colorIcon) - .sizeDp(20)) + b.settings.setImageDrawable( + IconicsDrawable(activity, CommunityMaterial.Icon.cmd_cog_outline).apply { + colorAttr(activity, R.attr.colorIcon) + sizeDp = 20 + } + ) - b.bellSync.setImageDrawable(IconicsDrawable(activity, SzkolnyFont.Icon.szf_alarm_bell_outline) - .colorAttr(activity, R.attr.colorIcon) - .sizeDp(20)) + b.bellSync.setImageDrawable( + IconicsDrawable(activity, SzkolnyFont.Icon.szf_alarm_bell_outline).apply { + colorAttr(activity, R.attr.colorIcon) + sizeDp = 20 + } + ) - b.showCounter.setImageDrawable(IconicsDrawable(activity, CommunityMaterial.Icon.cmd_fullscreen) - .colorAttr(activity, R.attr.colorIcon) - .sizeDp(20)) + b.showCounter.setImageDrawable( + IconicsDrawable(activity, CommunityMaterial.Icon2.cmd_fullscreen).apply { + colorAttr(activity, R.attr.colorIcon) + sizeDp = 20 + } + ) b.bellSync.setOnClickListener { BellSyncTimeChooseDialog( diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/homework/HomeworkFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/homework/HomeworkFragment.kt index 30abcd02..c8a62def 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/homework/HomeworkFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/homework/HomeworkFragment.kt @@ -12,7 +12,7 @@ import android.view.ViewGroup import android.widget.Toast import androidx.fragment.app.Fragment import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial -import com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont +import eu.szkolny.font.SzkolnyFont import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -100,7 +100,7 @@ class HomeworkFragment : Fragment(), CoroutineScope { bottomBar.apply { fabEnable = true fabExtendedText = getString(R.string.add) - fabIcon = CommunityMaterial.Icon2.cmd_plus + fabIcon = CommunityMaterial.Icon3.cmd_plus } setFabOnClickListener(View.OnClickListener { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginFormFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginFormFragment.kt index 8776f355..9e00200b 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginFormFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginFormFragment.kt @@ -97,11 +97,12 @@ class LoginFormFragment : Fragment(), CoroutineScope { b.textEdit.id = credential.name b.textEdit.setText(arguments?.getString(credential.keyName) ?: "") - b.textLayout.startIconDrawable = IconicsDrawable(activity) - .icon(credential.icon) - .sizeDp(24) - .paddingDp(2) - .colorAttr(activity, R.attr.colorOnBackground) + b.textLayout.startIconDrawable = IconicsDrawable(activity).apply { + icon = credential.icon + sizeDp = 24 + paddingDp = 2 + colorAttr(activity, R.attr.colorOnBackground) + } this.b.formContainer.addView(b.root) credentials[credential] = b diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginInfo.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginInfo.kt index 949848a5..77036f19 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginInfo.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginInfo.kt @@ -110,7 +110,7 @@ object LoginInfo { FormField( keyName = "accountPin", name = R.string.login_hint_pin, - icon = CommunityMaterial.Icon2.cmd_lock, + icon = CommunityMaterial.Icon2.cmd_lock_outline, emptyText = R.string.login_error_no_pin, invalidText = R.string.login_error_incorrect_pin, errorCodes = mapOf(), @@ -157,7 +157,7 @@ object LoginInfo { FormField( keyName = "symbol", name = R.string.login_hint_symbol, - icon = CommunityMaterial.Icon2.cmd_school, + icon = CommunityMaterial.Icon3.cmd_school_outline, emptyText = R.string.login_error_no_symbol, invalidText = R.string.login_error_incorrect_symbol, errorCodes = mapOf( @@ -170,7 +170,7 @@ object LoginInfo { FormField( keyName = "devicePin", name = R.string.login_hint_pin, - icon = CommunityMaterial.Icon2.cmd_lock, + icon = CommunityMaterial.Icon2.cmd_lock_outline, emptyText = R.string.login_error_no_pin, invalidText = R.string.login_error_incorrect_pin, errorCodes = mapOf( @@ -252,7 +252,7 @@ object LoginInfo { FormField( keyName = "serverName", name = R.string.login_hint_address, - icon = CommunityMaterial.Icon2.cmd_web, + icon = CommunityMaterial.Icon3.cmd_web, emptyText = R.string.login_error_no_address, invalidText = R.string.login_error_incorrect_address, errorCodes = mapOf( diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginPrizeFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginPrizeFragment.kt index b9fdf43a..1c9634fc 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginPrizeFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginPrizeFragment.kt @@ -10,7 +10,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment -import coil.api.load +import coil.load import com.google.android.material.dialog.MaterialAlertDialogBuilder import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/viewholder/PlatformViewHolder.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/viewholder/PlatformViewHolder.kt index ea8a063d..2c08c27e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/viewholder/PlatformViewHolder.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/viewholder/PlatformViewHolder.kt @@ -9,7 +9,7 @@ import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView -import coil.api.load +import coil.load import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.databinding.LoginPlatformItemBinding import pl.szczodrzynski.edziennik.ui.modules.grades.viewholder.BindableViewHolder diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt index b2623b64..2fcadf55 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt @@ -65,9 +65,10 @@ class MessageFragment : Fragment(), CoroutineScope { if (!isAdded) return b.closeButton.setImageDrawable( - IconicsDrawable(activity, CommunityMaterial.Icon2.cmd_window_close) - .colorAttr(activity, android.R.attr.textColorSecondary) - .sizeDp(12) + IconicsDrawable(activity, CommunityMaterial.Icon3.cmd_window_close).apply { + colorAttr(activity, android.R.attr.textColorSecondary) + sizeDp = 12 + } ) b.closeButton.setOnClickListener { activity.navigateUp() } @@ -230,7 +231,7 @@ class MessageFragment : Fragment(), CoroutineScope { bottomBar.apply { fabEnable = true fabExtendedText = getString(R.string.messages_reply) - fabIcon = CommunityMaterial.Icon2.cmd_reply + fabIcon = CommunityMaterial.Icon3.cmd_reply_outline } setFabOnClickListener(View.OnClickListener { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessagesFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessagesFragment.kt index 043cce7d..add36a3c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessagesFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessagesFragment.kt @@ -97,7 +97,7 @@ class MessagesFragment : Fragment(), CoroutineScope { bottomBar.apply { fabEnable = true fabExtendedText = getString(R.string.compose) - fabIcon = CommunityMaterial.Icon2.cmd_pencil_outline + fabIcon = CommunityMaterial.Icon3.cmd_pencil_outline } setFabOnClickListener(View.OnClickListener { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/compose/MessagesComposeFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/compose/MessagesComposeFragment.kt index 96898871..942876f2 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/compose/MessagesComposeFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/compose/MessagesComposeFragment.kt @@ -316,7 +316,7 @@ class MessagesComposeFragment : Fragment(), CoroutineScope { activity.navView.bottomBar.apply { fabEnable = true fabExtendedText = getString(R.string.messages_compose_send) - fabIcon = CommunityMaterial.Icon2.cmd_send + fabIcon = CommunityMaterial.Icon3.cmd_send_outline setFabOnClickListener(View.OnClickListener { sendMessage() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsLicenseActivity.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsLicenseActivity.kt index eb1a23e1..2e5aaf6f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsLicenseActivity.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsLicenseActivity.kt @@ -38,10 +38,11 @@ class SettingsLicenseActivity : MaterialAboutActivity() { license: OpenSourceLicense, libraryUrl: String): MaterialAboutCard { val licenseItem = MaterialAboutActionItem.Builder() - .icon(IconicsDrawable(this) - .icon(CommunityMaterial.Icon.cmd_book_outline) - .colorInt(foregroundColor) - .sizeDp(18)) + .icon(IconicsDrawable(this).apply { + icon = CommunityMaterial.Icon.cmd_book_outline + colorInt = foregroundColor + sizeDp = 18 + }) .setIconGravity(MaterialAboutActionItem.GRAVITY_TOP) .text(libraryTitle) .subText(String.format(getString(license.resourceId), copyrightYear, copyrightName)) @@ -78,12 +79,6 @@ class SettingsLicenseActivity : MaterialAboutActivity() { "Applandeo sp. z o.o.", OpenSourceLicense.APACHE_2, "https://github.com/Applandeo/Material-Calendar-View/"), - createLicenseCard(this, - "Android-Job", - "2007-2017", - "Evernote Corporation", - OpenSourceLicense.APACHE_2, - "https://github.com/evernote/android-job/"), createLicenseCard(this, "Custom Activity On Crash", "", @@ -150,12 +145,6 @@ class SettingsLicenseActivity : MaterialAboutActivity() { "Arthur Teplitzki, 2013 Edmodo, Inc.", OpenSourceLicense.APACHE_2, "https://github.com/ArthurHub/Android-Image-Cropper/"), - createLicenseCard(this, - "Material Tap Target Prompt", - "2016-2018", - "Samuel Wall", - OpenSourceLicense.APACHE_2, - "https://github.com/sjwall/MaterialTapTargetPrompt/"), createLicenseCard(this, "Android Swipe Layout", "2014", diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java index 555bc3fd..d009cdf1 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java @@ -21,16 +21,15 @@ import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem; import com.danielstone.materialaboutlibrary.items.MaterialAboutActionSwitchItem; import com.danielstone.materialaboutlibrary.items.MaterialAboutItem; import com.danielstone.materialaboutlibrary.items.MaterialAboutItemOnClickAction; -import com.danielstone.materialaboutlibrary.items.MaterialAboutProfileItem; import com.danielstone.materialaboutlibrary.items.MaterialAboutSwitchItem; import com.danielstone.materialaboutlibrary.items.MaterialAboutTitleItem; import com.danielstone.materialaboutlibrary.model.MaterialAboutCard; import com.danielstone.materialaboutlibrary.model.MaterialAboutList; -import com.mikepenz.iconics.IconicsColor; import com.mikepenz.iconics.IconicsDrawable; -import com.mikepenz.iconics.IconicsSize; +import com.mikepenz.iconics.typeface.IIcon; import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial; -import com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont; +import com.mikepenz.iconics.utils.IconicsConvertersKt; +import com.mikepenz.iconics.utils.IconicsDrawableExtensionsKt; import com.theartofdev.edmodo.cropper.CropImage; import com.theartofdev.edmodo.cropper.CropImageView; import com.wdullaer.materialdatetimepicker.time.TimePickerDialog; @@ -41,6 +40,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import eu.szkolny.font.SzkolnyFont; +import kotlin.Unit; import pl.szczodrzynski.edziennik.App; import pl.szczodrzynski.edziennik.BuildConfig; import pl.szczodrzynski.edziennik.ExtensionsKt; @@ -91,6 +92,15 @@ public class SettingsNewFragment extends MaterialAboutFragment { private int secondaryTextOnPrimaryBg = -1; private int iconSizeDp = 20; + private IconicsDrawable icon(IIcon icon, int sizeDp, int color) { + return new IconicsDrawable(activity).apply((drawable) -> { + drawable.setIcon(icon); + IconicsConvertersKt.setSizeDp(drawable, sizeDp); + IconicsDrawableExtensionsKt.setColorInt(drawable, color); + return Unit.INSTANCE; + }); + } + private MaterialAboutCard getCardWithItems(CharSequence title, ArrayList items, boolean primaryColor) { MaterialAboutCard card = new MaterialAboutCard.Builder().title(title).cardColor(0xff1976D2).build(); card.getItems().addAll(items); @@ -121,10 +131,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { return new MaterialAboutActionItem( getString(R.string.settings_more_text), null, - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_chevron_down) - .size(IconicsSize.dp(14)) - .color(IconicsColor.colorInt(iconColor)), + icon(CommunityMaterial.Icon.cmd_chevron_down, 14, iconColor), onClickAction ); } @@ -156,12 +163,12 @@ public class SettingsNewFragment extends MaterialAboutFragment { roundDrawable.setCircular(true); return roundDrawable;*/ } - private MaterialAboutProfileItem profileCardTitleItem; + private MaterialAboutTitleItem profileCardTitleItem; private ArrayList getProfileCard(boolean expandedOnly) { ArrayList items = new ArrayList<>(); if (!expandedOnly) { - profileCardTitleItem = new MaterialAboutProfileItem( + profileCardTitleItem = new MaterialAboutTitleItem( app.getProfile().getName(), app.getProfile().getSubname(), getProfileDrawable() @@ -210,10 +217,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { new MaterialAboutActionItem( getString(R.string.settings_profile_change_password_text), getString(R.string.settings_profile_change_password_subtext), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_key_variant) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) + icon(CommunityMaterial.Icon2.cmd_key_variant, iconSizeDp, iconColor) ) .setOnClickAction(() -> { @@ -224,10 +228,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { new MaterialAboutActionItem( getString(R.string.settings_add_student_text), getString(R.string.settings_add_student_subtext), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_account_plus_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) + icon(CommunityMaterial.Icon.cmd_account_plus_outline, iconSizeDp, iconColor) ) .setOnClickAction(() -> { startActivity(new Intent(activity, LoginActivity.class)); @@ -238,10 +239,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { new MaterialAboutActionItem( getString(R.string.settings_profile_notifications_text), getString(R.string.settings_profile_notifications_subtext), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_filter_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) + icon(CommunityMaterial.Icon2.cmd_filter_outline, iconSizeDp, iconColor) ) .setOnClickAction(() -> { new NotificationFilterDialog(activity, null, null); @@ -252,10 +250,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { new MaterialAboutActionItem( getString(R.string.settings_profile_remove_text), getString(R.string.settings_profile_remove_subtext), - new IconicsDrawable(activity) - .icon(SzkolnyFont.Icon.szf_delete_empty_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) + icon(SzkolnyFont.Icon.szf_delete_empty_outline, iconSizeDp, iconColor) ) .setOnClickAction(() -> { new ProfileRemoveDialog(activity, app.getProfile().getId(), app.getProfile().getName(), false); @@ -267,20 +262,17 @@ public class SettingsNewFragment extends MaterialAboutFragment { else { items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_profile_sync_text), - getString(R.string.settings_profile_sync_subtext), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_account_convert) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_profile_sync_text) + .subText(R.string.settings_profile_sync_subtext) + .icon(icon(CommunityMaterial.Icon.cmd_account_convert, iconSizeDp, iconColor)) .setChecked(app.getProfile().getSyncEnabled()) - .setOnChangeAction(((isChecked, tag) -> { + .setOnCheckedChanged(((item, isChecked) -> { app.getProfile().setSyncEnabled(isChecked); app.profileSave(); return true; })) + .build() ); } @@ -300,20 +292,17 @@ public class SettingsNewFragment extends MaterialAboutFragment { Date today = Date.getToday(); if (today.month == 12 || today.month == 1) { items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_theme_snowfall_text), - getString(R.string.settings_theme_snowfall_subtext), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_snowflake) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_theme_snowfall_text) + .subText(R.string.settings_theme_snowfall_subtext) + .icon(icon(CommunityMaterial.Icon3.cmd_snowflake, iconSizeDp, iconColor)) .setChecked(app.getConfig().getUi().getSnowfall()) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getConfig().getUi().setSnowfall(isChecked); activity.recreate(); return true; }) + .build() ); } @@ -321,10 +310,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { new MaterialAboutActionItem( getString(R.string.settings_theme_theme_text), Themes.INSTANCE.getThemeName(activity), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_palette_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) + icon(CommunityMaterial.Icon3.cmd_palette_outline, iconSizeDp, iconColor) ) .setOnClickAction(() -> { new MaterialDialog.Builder(activity) @@ -343,24 +329,21 @@ public class SettingsNewFragment extends MaterialAboutFragment { ); items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_theme_mini_drawer_text), - getString(R.string.settings_theme_mini_drawer_subtext), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_dots_vertical) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) - .setChecked(app.getConfig().getUi().getMiniMenuVisible()) - .setOnChangeAction((isChecked, tag) -> { - // 0,1 1 - // 0,0 0 - // 1,1 0 - // 1,0 1 - app.getConfig().getUi().setMiniMenuVisible(isChecked); - activity.getNavView().drawer.setMiniDrawerVisiblePortrait(isChecked); - return true; - }) + new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_theme_mini_drawer_text) + .subText(R.string.settings_theme_mini_drawer_subtext) + .icon(icon(CommunityMaterial.Icon.cmd_dots_vertical, iconSizeDp, iconColor)) + .setChecked(app.getConfig().getUi().getMiniMenuVisible()) + .setOnCheckedChanged((item, isChecked) -> { + // 0,1 1 + // 0,0 0 + // 1,1 0 + // 1,0 1 + app.getConfig().getUi().setMiniMenuVisible(isChecked); + activity.getNavView().drawer.setMiniDrawerVisiblePortrait(isChecked); + return true; + }) + .build() ); items.add(getMoreItem(() -> addCardItems(CARD_THEME, getThemeCard(true)))); @@ -371,10 +354,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { new MaterialAboutActionItem( getString(R.string.settings_theme_mini_drawer_buttons_text), null, - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_format_list_checks) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) + icon(CommunityMaterial.Icon2.cmd_format_list_checks, iconSizeDp, iconColor) ) .setOnClickAction(() -> { List buttonIds = new ArrayList<>(); @@ -435,10 +415,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { new MaterialAboutActionItem( getString(R.string.settings_theme_drawer_header_text), null, - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_image_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) + icon(CommunityMaterial.Icon2.cmd_image_outline, iconSizeDp, iconColor) ) .setOnClickAction(() -> { if (app.getConfig().getUi().getHeaderBackground() != null) { @@ -469,10 +446,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { new MaterialAboutActionItem( getString(R.string.settings_theme_app_background_text), getString(R.string.settings_theme_app_background_subtext), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_image_filter_hdr) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) + icon(CommunityMaterial.Icon2.cmd_image_filter_hdr, iconSizeDp, iconColor) ) .setOnClickAction(() -> { if (app.getConfig().getUi().getAppBackground() != null) { @@ -496,19 +470,15 @@ public class SettingsNewFragment extends MaterialAboutFragment { ); items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_theme_open_drawer_on_back_pressed_text), - null, - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_menu_open) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + new MaterialAboutSwitchItem.Builder( ) + .text(R.string.settings_theme_open_drawer_on_back_pressed_text) + .icon(icon(CommunityMaterial.Icon3.cmd_menu_open, iconSizeDp, iconColor)) .setChecked(app.getConfig().getUi().getOpenDrawerOnBackPressed()) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getConfig().getUi().setOpenDrawerOnBackPressed(isChecked); return true; }) + .build() ); } return items; @@ -548,20 +518,17 @@ public class SettingsNewFragment extends MaterialAboutFragment { ); } private MaterialAboutItem getSyncCardWifiItem() { - return new MaterialAboutSwitchItem( - getString(R.string.settings_sync_wifi_text), - getString(R.string.settings_sync_wifi_subtext), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_wifi_strength_2) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + return new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_sync_wifi_text) + .subText(R.string.settings_sync_wifi_subtext) + .icon(icon(CommunityMaterial.Icon3.cmd_wifi_strength_2, iconSizeDp, iconColor)) .setChecked(app.getConfig().getSync().getOnlyWifi()) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getConfig().getSync().setOnlyWifi(isChecked); SyncWorker.Companion.rescheduleNext(app); return true; - }); + }) + .build(); } private MaterialAboutActionSwitchItem syncCardIntervalItem; private MaterialAboutActionSwitchItem syncCardQuietHoursItem; @@ -569,14 +536,11 @@ public class SettingsNewFragment extends MaterialAboutFragment { ArrayList items = new ArrayList<>(); if (!expandedOnly) { - syncCardIntervalItem = new MaterialAboutActionSwitchItem( - getString(R.string.settings_sync_sync_interval_text), - getString(R.string.settings_sync_sync_interval_subtext_disabled), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_download_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ); + syncCardIntervalItem = new MaterialAboutActionSwitchItem.Builder() + .text(R.string.settings_sync_sync_interval_text) + .subText(R.string.settings_sync_sync_interval_subtext_disabled) + .icon(icon(CommunityMaterial.Icon.cmd_download_outline, iconSizeDp, iconColor)) + .build(); syncCardIntervalItem.setSubTextChecked(getSyncCardIntervalSubText()); syncCardIntervalItem.setChecked(app.getConfig().getSync().getEnabled()); syncCardIntervalItem.setOnClickAction(() -> { @@ -625,7 +589,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { }) .show(); }); - syncCardIntervalItem.setOnChangeAction((isChecked, tag) -> { + syncCardIntervalItem.setOnCheckedChangedAction((item, isChecked) -> { if (isChecked && !app.getConfig().getSync().getEnabled()) { addCardItem(CARD_SYNC, 1, getSyncCardWifiItem()); } @@ -646,10 +610,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { new MaterialAboutSwitchItem( "Cisza na lekcjach", "Nie odtwarzaj dźwięku powiadomień podczas lekcji", - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_volume_off) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) + icon(CommunityMaterial.Icon2.cmd_volume_off, iconSizeDp, iconColor) ) .setChecked(app.appConfig.quietDuringLessons) .setOnChangeAction((isChecked) -> { @@ -660,14 +621,11 @@ public class SettingsNewFragment extends MaterialAboutFragment { );*/ - syncCardQuietHoursItem = new MaterialAboutActionSwitchItem( - getString(R.string.settings_sync_quiet_hours_text), - getString(R.string.settings_sync_quiet_hours_subtext_disabled), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_bell_sleep_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ); + syncCardQuietHoursItem = new MaterialAboutActionSwitchItem.Builder() + .text(R.string.settings_sync_quiet_hours_text) + .subText(R.string.settings_sync_quiet_hours_subtext_disabled) + .icon(icon(CommunityMaterial.Icon.cmd_bell_sleep_outline, iconSizeDp, iconColor)) + .build(); syncCardQuietHoursItem.setChecked(app.getConfig().getSync().getQuietHoursEnabled()); syncCardQuietHoursItem.setSubTextChecked(getSyncCardQuietHoursSubText()); syncCardQuietHoursItem.setOnClickAction(() -> { @@ -707,7 +665,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { }) .show(); }); - syncCardQuietHoursItem.setOnChangeAction((isChecked, tag) -> { + syncCardQuietHoursItem.setOnCheckedChangedAction((item, isChecked) -> { app.getConfig().getSync().setQuietHoursEnabled(isChecked); if (isChecked && app.getConfig().getSync().getQuietHoursStart() == null) { app.getConfig().getSync().setQuietHoursStart(new Time(22, 30, 0)); @@ -723,10 +681,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { new MaterialAboutActionItem( getString(R.string.settings_sync_web_push_text), getString(R.string.settings_sync_web_push_subtext), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_laptop) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) + icon(CommunityMaterial.Icon2.cmd_laptop, iconSizeDp, iconColor) ) .setOnClickAction(() -> { activity.loadTarget(MainActivity.TARGET_WEB_PUSH, null); @@ -741,10 +696,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { new MaterialAboutActionItem( "Dźwięk powiadomień", "Szkolny.eu", - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_volume_high) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) + icon(CommunityMaterial.Icon2.cmd_volume_high, iconSizeDp, iconColor) ) .setOnClickAction(() -> { @@ -752,20 +704,16 @@ public class SettingsNewFragment extends MaterialAboutFragment { );*/ items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_sync_updates_text), - null, - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_cellphone_arrow_down) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_sync_updates_text) + .icon(icon(CommunityMaterial.Icon.cmd_cellphone_arrow_down, iconSizeDp, iconColor)) .setChecked(app.getConfig().getSync().getNotifyAboutUpdates()) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getConfig().getSync().setNotifyAboutUpdates(isChecked); UpdateWorker.Companion.rescheduleNext(app); return true; }) + .build() ); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { @@ -773,10 +721,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { new MaterialAboutActionItem( getString(R.string.settings_sync_notifications_settings_text), getString(R.string.settings_sync_notifications_settings_subtext), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_settings_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) + icon(CommunityMaterial.Icon.cmd_cog_outline, iconSizeDp, iconColor) ) .setOnClickAction(() -> { String channel = app.getNotificationChannelsManager().getData().getKey(); @@ -846,16 +791,12 @@ public class SettingsNewFragment extends MaterialAboutFragment { ); } private MaterialAboutItem getRegisterCardSharedEventsItem() { - return new MaterialAboutSwitchItem( - getString(R.string.settings_register_shared_events_text), - getString(R.string.settings_register_shared_events_subtext), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_share_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + return new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_register_shared_events_text) + .subText(R.string.settings_register_shared_events_subtext) + .icon(icon(CommunityMaterial.Icon3.cmd_share_outline, iconSizeDp, iconColor)) .setChecked(app.getProfile().getEnableSharedEvents()) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getProfile().setEnableSharedEvents(isChecked); app.profileSave(); if (isChecked) new MaterialDialog.Builder(activity) @@ -869,7 +810,8 @@ public class SettingsNewFragment extends MaterialAboutFragment { .positiveText(R.string.ok) .show(); return true; - }); + }) + .build(); } private MaterialAboutSwitchItem registerCardAllowRegistrationItem; @@ -880,31 +822,22 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(new MaterialAboutActionItem( getString(R.string.menu_grades_config), null, - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_numeric_5_box_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) + icon(CommunityMaterial.Icon3.cmd_numeric_5_box_outline, iconSizeDp, iconColor) ).setOnClickAction(() -> new GradesConfigDialog(activity, false, null, null))); items.add(new MaterialAboutActionItem( getString(R.string.menu_attendance_config), null, - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_calendar_remove_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) + icon(CommunityMaterial.Icon.cmd_calendar_remove_outline, iconSizeDp, iconColor) ).setOnClickAction(() -> new AttendanceConfigDialog(activity, false, null, null))); - registerCardAllowRegistrationItem = new MaterialAboutSwitchItem( - getString(R.string.settings_register_allow_registration_text), - getString(R.string.settings_register_allow_registration_subtext), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_account_circle_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ); + registerCardAllowRegistrationItem = new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_register_allow_registration_text) + .subText(R.string.settings_register_allow_registration_subtext) + .icon(icon(CommunityMaterial.Icon.cmd_account_circle_outline, iconSizeDp, iconColor)) + .build(); registerCardAllowRegistrationItem.setChecked(app.getProfile().getRegistration() == REGISTRATION_ENABLED); - registerCardAllowRegistrationItem.setOnChangeAction((isChecked, tag) -> { + registerCardAllowRegistrationItem.setOnCheckedChangedAction((item, isChecked) -> { if (isChecked) new MaterialDialog.Builder(activity) .title(getString(R.string.settings_register_allow_registration_dialog_enabled_title)) .content(getString(R.string.settings_register_allow_registration_dialog_enabled_text)) @@ -958,10 +891,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { registerCardBellSyncItem = new MaterialAboutActionItem( getString(R.string.settings_register_bell_sync_text), getRegisterCardBellSyncSubText(), - new IconicsDrawable(activity) - .icon(SzkolnyFont.Icon.szf_alarm_bell_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) + icon(SzkolnyFont.Icon.szf_alarm_bell_outline, iconSizeDp, iconColor) ); registerCardBellSyncItem.setOnClickAction(() -> { new MaterialDialog.Builder(activity) @@ -1025,55 +955,44 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(registerCardBellSyncItem); items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_register_count_in_seconds_text), - getString(R.string.settings_register_count_in_seconds_subtext), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_timer) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_register_count_in_seconds_text) + .subText(R.string.settings_register_count_in_seconds_subtext) + .icon(icon(CommunityMaterial.Icon3.cmd_timer, iconSizeDp, iconColor)) .setChecked(app.getConfig().getTimetable().getCountInSeconds()) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getConfig().getTimetable().setCountInSeconds(isChecked); return true; }) + .build() ); if (app.getProfile().getLoginStoreType() == LoginStore.LOGIN_TYPE_LIBRUS) { items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_register_show_teacher_absences_text), - null, - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_account_arrow_right_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_register_show_teacher_absences_text) + .icon(icon(CommunityMaterial.Icon.cmd_account_arrow_right_outline, iconSizeDp, iconColor)) .setChecked(app.getProfile().getStudentData("showTeacherAbsences", true)) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getProfile().putStudentData("showTeacherAbsences", isChecked); app.profileSave(); return true; }) + .build() ); } if (App.Companion.getDevMode()) { items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_register_hide_sticks_from_old), - null, - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_numeric_1_box_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_register_hide_sticks_from_old) + .icon(icon(CommunityMaterial.Icon3.cmd_numeric_1_box_outline, iconSizeDp, iconColor)) .setChecked(app.getConfig().forProfile().getGrades().getHideSticksFromOld()) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getConfig().forProfile().getGrades().setHideSticksFromOld(isChecked); return true; }) + .build() ); } @@ -1097,20 +1016,13 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(new MaterialAboutTitleItem.Builder() .text(R.string.app_name) .desc(R.string.settings_about_title_subtext) - .textColor(primaryTextOnPrimaryBg) - .descColor(secondaryTextOnPrimaryBg) .icon(R.mipmap.ic_splash) .build()); pref_about_version = new MaterialAboutActionItem.Builder() .text(R.string.settings_about_version_text) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) .subText(BuildConfig.VERSION_NAME + ", " + BuildConfig.BUILD_TYPE) - .icon(new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_information_outline) - .color(IconicsColor.colorInt(primaryTextOnPrimaryBg)) - .size(IconicsSize.dp(iconSizeDp))) + .icon(icon(CommunityMaterial.Icon2.cmd_information_outline, iconSizeDp, primaryTextOnPrimaryBg)) .build(); final int[] clickCounter = {0}; pref_about_version.setOnClickAction(() -> { @@ -1129,36 +1041,21 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_privacy_policy_text) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) - .icon(new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_shield_outline) - .color(IconicsColor.colorInt(primaryTextOnPrimaryBg)) - .size(IconicsSize.dp(iconSizeDp))) + .icon(icon(CommunityMaterial.Icon3.cmd_shield_outline, iconSizeDp, primaryTextOnPrimaryBg)) .setOnClickAction(ConvenienceBuilder.createWebsiteOnClickAction(activity, Uri.parse("https://szkolny.eu/privacy-policy"))) .build()); items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_discord_text) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) .subText(R.string.settings_about_discord_subtext) - .icon(new IconicsDrawable(activity) - .icon(SzkolnyFont.Icon.szf_discord_outline) - .color(IconicsColor.colorInt(primaryTextOnPrimaryBg)) - .size(IconicsSize.dp(iconSizeDp))) + .icon(icon(SzkolnyFont.Icon.szf_discord_outline, iconSizeDp, primaryTextOnPrimaryBg)) .setOnClickAction(ConvenienceBuilder.createWebsiteOnClickAction(activity, Uri.parse("https://szkolny.eu/discord"))) .build()); items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_language_text) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) .subText(R.string.settings_about_language_subtext) - .icon(new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_translate) - .color(IconicsColor.colorInt(primaryTextOnPrimaryBg)) - .size(IconicsSize.dp(iconSizeDp))) + .icon(icon(CommunityMaterial.Icon3.cmd_translate, iconSizeDp, primaryTextOnPrimaryBg)) .setOnClickAction(() -> { new MaterialDialog.Builder(activity) .title(getString(R.string.settings_about_language_dialog_title)) @@ -1193,12 +1090,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_update_text) .subText(R.string.settings_about_update_subtext) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) - .icon(new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_update) - .color(IconicsColor.colorInt(primaryTextOnPrimaryBg)) - .size(IconicsSize.dp(iconSizeDp))) + .icon(icon(CommunityMaterial.Icon3.cmd_update, iconSizeDp, primaryTextOnPrimaryBg)) .setOnClickAction(() -> { //open browser or intent here NetworkUtils net = new NetworkUtils(app); @@ -1218,23 +1110,13 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_changelog_text) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) - .icon(new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_radar) - .color(IconicsColor.colorInt(primaryTextOnPrimaryBg)) - .size(IconicsSize.dp(iconSizeDp))) + .icon(icon(CommunityMaterial.Icon3.cmd_radar, iconSizeDp, primaryTextOnPrimaryBg)) .setOnClickAction(() -> new ChangelogDialog(activity, null, null)) .build()); items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_licenses_text) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) - .icon(new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_code_braces) - .color(IconicsColor.colorInt(primaryTextOnPrimaryBg)) - .size(IconicsSize.dp(iconSizeDp))) + .icon(icon(CommunityMaterial.Icon.cmd_code_braces, iconSizeDp, primaryTextOnPrimaryBg)) .setOnClickAction(() -> { Intent intent = new Intent(activity, SettingsLicenseActivity.class); startActivity(intent); @@ -1243,10 +1125,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { /*items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_intro_text) - .icon(new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_projector_screen) - .color(IconicsColor.colorInt(iconColor)) - .size(IconicsSize.dp(iconSizeDp))) + .icon(icon(CommunityMaterial.Icon2.cmd_projector_screen, iconSizeDp, iconColor)) .setOnClickAction(() -> { if (tryingToDevMode[0]) { if (getParentFragment() instanceof SettingsGeneralFragment) { @@ -1267,12 +1146,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_crash_text) .subText(R.string.settings_about_crash_subtext) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) - .icon(new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_bug_outline) - .color(IconicsColor.colorInt(primaryTextOnPrimaryBg)) - .size(IconicsSize.dp(iconSizeDp))) + .icon(icon(CommunityMaterial.Icon.cmd_bug_outline, iconSizeDp, primaryTextOnPrimaryBg)) .setOnClickAction(() -> { throw new RuntimeException("MANUAL CRASH"); }) @@ -1304,11 +1178,6 @@ public class SettingsNewFragment extends MaterialAboutFragment { return materialAboutList; } - @Override - protected int getTheme() { - return Themes.INSTANCE.getAppTheme(); - } - /* _____ _ ____ _ _ / ____| | | | _ \ | | | | | | _ _ ___| |_ ___ _ __ ___ | |_) | __ _ ___| | ____ _ _ __ ___ _ _ _ __ __| |___ diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/TimetableFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/TimetableFragment.kt index 52441e25..d7b1b9a7 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/TimetableFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/TimetableFragment.kt @@ -17,9 +17,8 @@ import android.widget.Toast import androidx.fragment.app.Fragment import androidx.viewpager.widget.ViewPager import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial -import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial.Icon2 -import com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont import com.wdullaer.materialdatetimepicker.date.DatePickerDialog +import eu.szkolny.font.SzkolnyFont import kotlinx.coroutines.* import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.MainActivity @@ -192,7 +191,7 @@ class TimetableFragment : Fragment(), CoroutineScope { BottomSheetPrimaryItem(true) .withTitle(R.string.menu_generate_block_timetable) .withDescription(R.string.menu_generate_block_timetable_desc) - .withIcon(Icon2.cmd_table_large) + .withIcon(CommunityMaterial.Icon3.cmd_table_large) .withOnClickListener(View.OnClickListener { activity.bottomSheet.close() GenerateBlockTimetableDialog(activity) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/views/AttachmentAdapter.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/views/AttachmentAdapter.kt index 1975f39e..6f8bc4c7 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/views/AttachmentAdapter.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/views/AttachmentAdapter.kt @@ -11,11 +11,10 @@ import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import com.google.android.material.chip.Chip import com.mikepenz.iconics.IconicsDrawable -import com.mikepenz.iconics.typeface.IIcon import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial -import com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont import com.mikepenz.iconics.utils.paddingDp import com.mikepenz.iconics.utils.sizeDp +import eu.szkolny.font.SzkolnyFont import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -60,7 +59,7 @@ class AttachmentAdapter( val fileName = item.name.substringBefore(":http") // create an icon for the attachment - val icon: IIcon = when (Utils.getExtensionFromFileName(fileName)) { + val attachmentIcon = when (Utils.getExtensionFromFileName(fileName)) { "doc", "docx", "odt", "rtf" -> SzkolnyFont.Icon.szf_file_word_outline "xls", "xlsx", "ods" -> SzkolnyFont.Icon.szf_file_excel_outline "ppt", "pptx", "odp" -> SzkolnyFont.Icon.szf_file_powerpoint_outline @@ -70,7 +69,7 @@ class AttachmentAdapter( "jpg", "jpeg", "png", "bmp", "gif" -> SzkolnyFont.Icon.szf_file_image_outline "zip", "rar", "tar", "7z" -> SzkolnyFont.Icon.szf_zip_box_outline "html", "cpp", "c", "h", "css", "java", "py" -> SzkolnyFont.Icon.szf_file_code_outline - else -> CommunityMaterial.Icon.cmd_file_document_outline + else -> CommunityMaterial.Icon2.cmd_file_document_outline } b.chip.text = if (item.isDownloading) { @@ -82,15 +81,17 @@ class AttachmentAdapter( } ?: fileName } - b.chip.chipIcon = IconicsDrawable(context) - .icon(icon) - .colorAttr(context, R.attr.colorOnSurface) - .sizeDp(24) - .paddingDp(2) - b.chip.closeIcon = IconicsDrawable(context) - .icon(CommunityMaterial.Icon.cmd_check) - .colorAttr(context, R.attr.colorOnSurface) - .sizeDp(18) + b.chip.chipIcon = IconicsDrawable(context).apply { + icon = attachmentIcon + colorAttr(context, R.attr.colorOnSurface) + sizeDp = 24 + paddingDp = 2 + } + b.chip.closeIcon = IconicsDrawable(context).apply { + icon = CommunityMaterial.Icon.cmd_check + colorAttr(context, R.attr.colorOnSurface) + sizeDp = 18 + } b.chip.isCloseIconVisible = item.isDownloaded && !item.isDownloading // prevent progress bar flickering diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/notifications/WidgetNotificationsProvider.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/notifications/WidgetNotificationsProvider.kt index aec64aef..3832b6c7 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/notifications/WidgetNotificationsProvider.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/notifications/WidgetNotificationsProvider.kt @@ -48,10 +48,10 @@ class WidgetNotificationsProvider : AppWidgetProvider() { views.setImageViewBitmap( R.id.widgetNotificationsSync, - IconicsDrawable(context, CommunityMaterial.Icon.cmd_download_outline) - .colorInt(Color.WHITE) - .sizeDp(iconSize) - .toBitmap() + IconicsDrawable(context, CommunityMaterial.Icon.cmd_download_outline).apply { + colorInt = Color.WHITE + sizeDp = iconSize + }.toBitmap() ) views.setViewVisibility(R.id.widgetNotificationsLoading, View.GONE) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/timetable/WidgetTimetableFactory.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/timetable/WidgetTimetableFactory.java index 6f81bf2c..8a351b1f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/timetable/WidgetTimetableFactory.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/timetable/WidgetTimetableFactory.java @@ -24,13 +24,14 @@ import android.widget.RemoteViewsService; import androidx.annotation.DrawableRes; -import com.mikepenz.iconics.IconicsColor; import com.mikepenz.iconics.IconicsDrawable; -import com.mikepenz.iconics.IconicsSize; import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial; +import com.mikepenz.iconics.utils.IconicsConvertersKt; +import com.mikepenz.iconics.utils.IconicsDrawableExtensionsKt; import java.util.List; +import kotlin.Unit; import pl.szczodrzynski.edziennik.R; import pl.szczodrzynski.edziennik.utils.models.Date; import pl.szczodrzynski.edziennik.utils.models.ItemWidgetTimetableModel; @@ -126,6 +127,15 @@ public class WidgetTimetableFactory implements RemoteViewsService.RemoteViewsFac return resultBitmap; } + private Bitmap homeIconBitmap() { + return new IconicsDrawable(context).apply((drawable) -> { + IconicsConvertersKt.setColorRes(drawable, R.color.md_red_500); + IconicsConvertersKt.setSizeDp(drawable, 10); + IconicsDrawableExtensionsKt.icon(drawable, CommunityMaterial.Icon2.cmd_home); + return Unit.INSTANCE; + }).toBitmap(); + } + @Override public RemoteViews getViewAt(int i) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.row_widget_timetable_item); @@ -270,19 +280,19 @@ public class WidgetTimetableFactory implements RemoteViewsService.RemoteViewsFac if (lesson.eventColors.size() >= 1) { views.setViewVisibility(R.id.widgetTimetableEvent1, View.VISIBLE); if (lesson.eventColors.get(0) == -1) - views.setBitmap(R.id.widgetTimetableEvent1, "setImageBitmap", new IconicsDrawable(context).color(IconicsColor.colorRes(R.color.md_red_500)).size(IconicsSize.dp(10)).icon(CommunityMaterial.Icon2.cmd_home).toBitmap()); + views.setBitmap(R.id.widgetTimetableEvent1, "setImageBitmap", homeIconBitmap()); else views.setBitmap(R.id.widgetTimetableEvent1, "setImageBitmap", getColoredBitmap(context, R.drawable.event_color_circle, lesson.eventColors.get(0), eventIndicatorSize, eventIndicatorSize)); if (lesson.eventColors.size() >= 2) { views.setViewVisibility(R.id.widgetTimetableEvent2, View.VISIBLE); if (lesson.eventColors.get(1) == -1) - views.setBitmap(R.id.widgetTimetableEvent2, "setImageBitmap", new IconicsDrawable(context).color(IconicsColor.colorRes(R.color.md_red_500)).size(IconicsSize.dp(10)).icon(CommunityMaterial.Icon2.cmd_home).toBitmap()); + views.setBitmap(R.id.widgetTimetableEvent2, "setImageBitmap", homeIconBitmap()); else views.setBitmap(R.id.widgetTimetableEvent2, "setImageBitmap", getColoredBitmap(context, R.drawable.event_color_circle, lesson.eventColors.get(1), eventIndicatorSize, eventIndicatorSize)); if (lesson.eventColors.size() >= 3) { views.setViewVisibility(R.id.widgetTimetableEvent3, View.VISIBLE); if (lesson.eventColors.get(2) == -1) - views.setBitmap(R.id.widgetTimetableEvent3, "setImageBitmap", new IconicsDrawable(context).color(IconicsColor.colorRes(R.color.md_red_500)).size(IconicsSize.dp(10)).icon(CommunityMaterial.Icon2.cmd_home).toBitmap()); + views.setBitmap(R.id.widgetTimetableEvent3, "setImageBitmap", homeIconBitmap()); else views.setBitmap(R.id.widgetTimetableEvent3, "setImageBitmap", getColoredBitmap(context, R.drawable.event_color_circle, lesson.eventColors.get(2), eventIndicatorSize, eventIndicatorSize)); } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/timetable/WidgetTimetableProvider.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/timetable/WidgetTimetableProvider.kt index bc284ba2..daffae65 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/timetable/WidgetTimetableProvider.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/timetable/WidgetTimetableProvider.kt @@ -115,13 +115,21 @@ class WidgetTimetableProvider : AppWidgetProvider() { views.setOnClickPendingIntent(R.id.widgetTimetableSync, getPendingSelfIntent(context, ACTION_SYNC_DATA)) - views.setImageViewBitmap(R.id.widgetTimetableRefresh, IconicsDrawable(context, CommunityMaterial.Icon2.cmd_refresh) - .colorInt(Color.WHITE) - .sizeDp(if (config.bigStyle) 24 else 16).toBitmap()) + views.setImageViewBitmap( + R.id.widgetTimetableRefresh, + IconicsDrawable(context, CommunityMaterial.Icon3.cmd_refresh).apply { + colorInt = Color.WHITE + sizeDp = if (config.bigStyle) 24 else 16 + }.toBitmap() + ) - views.setImageViewBitmap(R.id.widgetTimetableSync, IconicsDrawable(context, CommunityMaterial.Icon.cmd_download_outline) - .colorInt(Color.WHITE) - .sizeDp(if (config.bigStyle) 24 else 16).toBitmap()) + views.setImageViewBitmap( + R.id.widgetTimetableSync, + IconicsDrawable(context, CommunityMaterial.Icon.cmd_download_outline).apply { + colorInt = Color.WHITE + sizeDp = if (config.bigStyle) 24 else 16 + }.toBitmap() + ) prepareAppWidget(app, appWidgetId, views, config, bellSyncDiffMillis) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/utils/SwipeRefreshLayoutNoIndicator.java b/app/src/main/java/pl/szczodrzynski/edziennik/utils/SwipeRefreshLayoutNoIndicator.java new file mode 100644 index 00000000..75192eec --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/utils/SwipeRefreshLayoutNoIndicator.java @@ -0,0 +1,208 @@ +/* + * Copyright 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package pl.szczodrzynski.edziennik.utils; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + +/** + * The SwipeRefreshLayout should be used whenever the user can refresh the + * contents of a view via a vertical swipe gesture. The activity that + * instantiates this view should add an OnRefreshListener to be notified + * whenever the swipe to refresh gesture is completed. The SwipeRefreshLayout + * will notify the listener each and every time the gesture is completed again; + * the listener is responsible for correctly determining when to actually + * initiate a refresh of its content. If the listener determines there should + * not be a refresh, it must call setRefreshing(false) to cancel any visual + * indication of a refresh. If an activity wishes to show just the progress + * animation, it should call setRefreshing(true). To disable the gesture and + * progress animation, call setEnabled(false) on the view. + *

+ * This layout should be made the parent of the view that will be refreshed as a + * result of the gesture and can only support one direct child. This view will + * also be made the target of the gesture and will be forced to match both the + * width and the height supplied in this layout. The SwipeRefreshLayout does not + * provide accessibility events; instead, a menu item must be provided to allow + * refresh of the content wherever this gesture is used. + *

+ */ +public class SwipeRefreshLayoutNoIndicator extends SwipeRefreshLayout { + + private SwipeRefreshLayoutNoTouch parent; + + @Override + public void setEnabled(boolean enabled) { + if (parent == null) + return; + parent.setEnabled(enabled); + super.setEnabled(enabled); + } + + public void setParent(SwipeRefreshLayoutNoTouch parent) { + this.parent = parent; + } + + /** + * Simple constructor to use when creating a SwipeRefreshLayout from code. + * + * @param context + */ + public SwipeRefreshLayoutNoIndicator(@NonNull Context context) { + this(context, null); + } + + /** + * Constructor that is called when inflating SwipeRefreshLayout from XML. + * + * @param context + * @param attrs + */ + public SwipeRefreshLayoutNoIndicator(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + ev.setSource(0x10000000); + boolean parentConsumed = parent.onInterceptTouchEvent(ev); + boolean superConsumed = super.onInterceptTouchEvent(ev); + return parentConsumed && superConsumed; + /*if (super.onInterceptTouchEvent(ev)) + return parent.onInterceptTouchEvent(ev); + return false;*/ + } + + @Override + public void requestDisallowInterceptTouchEvent(boolean b) { + parent.requestDisallowInterceptTouchEvent(b); + } + + // NestedScrollingParent + + @Override + public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) { + parent.onStartNestedScroll(child, target, nestedScrollAxes); + return !parent.isRefreshing() && super.onStartNestedScroll(child, target, nestedScrollAxes); + } + + @Override + public void onNestedScrollAccepted(View child, View target, int axes) { + parent.onNestedScrollAccepted(child, target, axes); + } + + @Override + public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) { + parent.onNestedPreScroll(target, dx, dy, consumed); + } + + @Override + public int getNestedScrollAxes() { + return parent.getNestedScrollAxes(); + } + + @Override + public void onStopNestedScroll(View target) { + parent.onStopNestedScroll(target); + } + + @Override + public void onNestedScroll(final View target, final int dxConsumed, final int dyConsumed, + final int dxUnconsumed, final int dyUnconsumed) { + parent.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed); + } + + // NestedScrollingChild + + @Override + public void setNestedScrollingEnabled(boolean enabled) { + if (parent == null) + return; + //parent.setNestedScrollingEnabled(enabled); + super.setNestedScrollingEnabled(enabled); + } + + @Override + public boolean isNestedScrollingEnabled() { + return parent.isNestedScrollingEnabled(); + } + + @Override + public boolean startNestedScroll(int axes) { + return parent.startNestedScroll(axes); + } + + @Override + public void stopNestedScroll() { + parent.stopNestedScroll(); + } + + @Override + public boolean hasNestedScrollingParent() { + return parent.hasNestedScrollingParent(); + } + + @Override + public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, + int dyUnconsumed, int[] offsetInWindow) { + return super.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow); + } + + @Override + public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) { + return super.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow); + } + + @Override + public boolean onNestedPreFling(View target, float velocityX, + float velocityY) { + return parent.onNestedPreFling(target, velocityX, velocityY); + } + + @Override + public boolean onNestedFling(View target, float velocityX, float velocityY, + boolean consumed) { + return parent.onNestedFling(target, velocityX, velocityY, consumed); + } + + @Override + public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) { + return parent.dispatchNestedFling(velocityX, velocityY, consumed); + } + + @Override + public boolean dispatchNestedPreFling(float velocityX, float velocityY) { + return parent.dispatchNestedPreFling(velocityX, velocityY); + } + + @Override + public boolean onTouchEvent(MotionEvent ev) { + ev.setSource(0x10000000); + /*boolean consumed = super.onTouchEvent(ev); + if (consumed) { + return false; + }*/ + return parent.onTouchEvent(ev); + } + + +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/utils/SwipeRefreshLayoutNoTouch.java b/app/src/main/java/pl/szczodrzynski/edziennik/utils/SwipeRefreshLayoutNoTouch.java new file mode 100644 index 00000000..0b2daf51 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/utils/SwipeRefreshLayoutNoTouch.java @@ -0,0 +1,51 @@ +package pl.szczodrzynski.edziennik.utils; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + + +public class SwipeRefreshLayoutNoTouch extends SwipeRefreshLayout { + public SwipeRefreshLayoutNoTouch(@NonNull Context context) { + super(context); + } + + public SwipeRefreshLayoutNoTouch(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + @Override + public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) { + return false; + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + if (ev.getSource() == 0x10000000) { + // forward the event to super + return super.onInterceptTouchEvent(ev); + } + // discard all the other events + return false; + + /*if (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) + return false; + super.onInterceptTouchEvent(ev); + return false;*/ + } + + @Override + public boolean onTouchEvent(MotionEvent ev) { + if (ev.getSource() == 0x10000000) { + // forward the event to super + return super.onTouchEvent(ev); + } + // discard all the other events + return false; + } +} diff --git a/app/src/main/res/layout/dialog_event_details.xml b/app/src/main/res/layout/dialog_event_details.xml index 11f57902..dc883137 100644 --- a/app/src/main/res/layout/dialog_event_details.xml +++ b/app/src/main/res/layout/dialog_event_details.xml @@ -206,6 +206,7 @@ app:flexWrap="wrap" app:justifyContent="flex_end"> + + + + + diff --git a/app/src/main/res/layout/event_list_item.xml b/app/src/main/res/layout/event_list_item.xml index 295ffdc2..f8f42ef9 100644 --- a/app/src/main/res/layout/event_list_item.xml +++ b/app/src/main/res/layout/event_list_item.xml @@ -73,14 +73,15 @@ android:textAppearance="@style/NavView.TextView.Medium" tools:text="Rozdział II: Panowanie Piastów i Jagiellonów.Przeniesiony z 11 grudnia. Nie wiem co się dzieje w tym roku nie będzie już religii w szkołach podstawowych w Polsce i Europie zachodniej Afryki" /> + diff --git a/app/src/main/res/layout/login_chooser_fragment.xml b/app/src/main/res/layout/login_chooser_fragment.xml index 27e6f309..6e83c68c 100644 --- a/app/src/main/res/layout/login_chooser_fragment.xml +++ b/app/src/main/res/layout/login_chooser_fragment.xml @@ -18,7 +18,7 @@ android:layout_marginHorizontal="24dp" android:layout_marginTop="32dp" app:iiv_color="@color/colorPrimary" - app:iiv_icon="cmd-school" + app:iiv_icon="cmd-school-outline" app:iiv_size="32dp" tools:srcCompat="@tools:sample/avatars" /> diff --git a/app/src/main/res/layout/login_form_fragment.xml b/app/src/main/res/layout/login_form_fragment.xml index 6bfb817f..ac4afd93 100644 --- a/app/src/main/res/layout/login_form_fragment.xml +++ b/app/src/main/res/layout/login_form_fragment.xml @@ -29,7 +29,7 @@ android:layout_height="32dp" android:layout_marginTop="32dp" app:iiv_color="@color/colorPrimary" - app:iiv_icon="cmd-account-circle" + app:iiv_icon="cmd-account-circle-outline" app:iiv_size="32dp" tools:srcCompat="@tools:sample/avatars" /> diff --git a/app/src/main/res/layout/login_platform_list_fragment.xml b/app/src/main/res/layout/login_platform_list_fragment.xml index 699177ff..7604f1c7 100644 --- a/app/src/main/res/layout/login_platform_list_fragment.xml +++ b/app/src/main/res/layout/login_platform_list_fragment.xml @@ -18,7 +18,7 @@ android:layout_marginHorizontal="24dp" android:layout_marginTop="32dp" app:iiv_color="@color/colorPrimary" - app:iiv_icon="cmd-tooltip-account" + app:iiv_icon="cmd-comment-account-outline" app:iiv_size="32dp" tools:srcCompat="@tools:sample/avatars" /> diff --git a/app/src/main/res/layout/login_summary_fragment.xml b/app/src/main/res/layout/login_summary_fragment.xml index 1b7aac65..174087e8 100644 --- a/app/src/main/res/layout/login_summary_fragment.xml +++ b/app/src/main/res/layout/login_summary_fragment.xml @@ -28,7 +28,7 @@ android:layout_marginHorizontal="24dp" android:layout_marginTop="32dp" app:iiv_color="@color/colorPrimary" - app:iiv_icon="cmd-account-check" + app:iiv_icon="cmd-account-check-outline" app:iiv_size="32dp" tools:srcCompat="@tools:sample/avatars" /> diff --git a/app/src/main/res/layout/message_fragment.xml b/app/src/main/res/layout/message_fragment.xml index a58f610f..bb252b11 100644 --- a/app/src/main/res/layout/message_fragment.xml +++ b/app/src/main/res/layout/message_fragment.xml @@ -217,7 +217,7 @@ android:layout_height="24dp" android:padding="4dp" app:iiv_color="?android:textColorSecondary" - app:iiv_icon="cmd-reply" + app:iiv_icon="cmd-reply-outline" tools:srcCompat="@android:drawable/ic_menu_revert" /> {cmd-alert-circle-outline} Wersja testowa
{cmd-android-studio} Wersja deweloperska \??? + Szkoda, opinie innych pomagają mi rozwijać aplikację. diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9983ecf0..512c6ade 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -111,12 +111,9 @@ ?colorAccent ?android:textColorPrimary - @style/Theme.Mal.Toolbar.Dark - @style/Theme.Mal.Toolbar.Light ?android:textColorPrimary ?android:textColorSecondary ?colorSurface - @color/dividerColor @drawable/timetable_lesson_bg_light #9f9f9f @@ -147,12 +144,9 @@ ?colorAccent ?android:textColorPrimary - @style/Theme.Mal.Toolbar.Dark - @style/Theme.Mal.Toolbar.Dark @color/primaryTextDark @color/secondaryTextDark ?colorSurface - @color/dividerColor @drawable/timetable_lesson_bg_dark #838383 diff --git a/app/src/main/res/xml/backup_descriptor.xml b/app/src/main/res/xml/backup_descriptor.xml index 9b85b4b7..f5417ebb 100644 --- a/app/src/main/res/xml/backup_descriptor.xml +++ b/app/src/main/res/xml/backup_descriptor.xml @@ -2,6 +2,4 @@ - - diff --git a/build.gradle b/build.gradle index c0fb9910..343e5fd5 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ buildscript { ext { - kotlin_version = '1.4.30' + kotlin_version = '1.4.31' release = [ versionName: "4.6.1", @@ -11,50 +11,9 @@ buildscript { setup = [ compileSdk: 30, - buildTools: "28.0.3", minSdk : 16, targetSdk : 30 ] - - versions = [ - gradleAndroid : '4.2.0-beta04', - - kotlin : ext.kotlin_version, - ktx : "1.3.2", - - androidX : '1.0.0', - annotation : '1.1.0', - recyclerView : '1.2.0-beta01', - material : '1.3.0', - appcompat : '1.3.0-beta01', - constraintLayout : '2.1.0-alpha2', - cardview : '1.0.0', - gridLayout : '1.0.0', - navigation : "2.0.0", - navigationFragment: "1.0.0", - legacy : "1.0.0", - - room : "2.2.6", - lifecycle : "2.3.0", - work : "2.5.0", - - firebase : '18.0.2', - firebasemessaging: "20.1.3", - play_services : "17.0.0", - - materialdialogs : "0.9.6.0", - materialdrawer : "817e45765c367034b03046aaea6e95eeabcb40e9", - iconics : "4.0.1", - font_cmd : "3.5.95.1-kotlin", - - navlib : "28cdab341470dffa5f331379fe9702482681d7de", - - gifdrawable : "1.2.15", - - retrofit : "2.6.4" - ] - versions.kotlin = '1.4.0' - versions.kotlin = '1.4.0' } repositories { @@ -62,11 +21,10 @@ buildscript { jcenter() } dependencies { - classpath "com.android.tools.build:gradle:${versions.gradleAndroid}" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" - classpath 'me.tatarka:gradle-retrolambda:3.7.0' + classpath "com.android.tools.build:gradle:4.2.0-beta06" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.3.5' - classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.0' + classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.1' } } diff --git a/cafebar/build.gradle b/cafebar/build.gradle deleted file mode 100644 index 4e992077..00000000 --- a/cafebar/build.gradle +++ /dev/null @@ -1,64 +0,0 @@ -apply plugin: 'com.android.library' - -/* - * CafeBar - * - * Copyright (c) 2017 Dani Mahardhika - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -group = 'com.github.danimahardhika' - -android { - compileSdkVersion setup.compileSdk - - defaultConfig { - minSdkVersion 16 - targetSdkVersion setup.targetSdk - versionCode 132 - versionName "1.3.2" - vectorDrawables.useSupportLibrary = true - - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - debugMinify { - debuggable = true - minifyEnabled = true - proguardFiles 'proguard-android.txt' - } - } - - lintOptions { - abortOnError false - } - - sourceSets { - main.res.srcDirs = [ - 'src/main/res', - 'src/main/res-public' - ] - } -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "com.google.android.material:material:${versions.material}" - implementation "androidx.cardview:cardview:${versions.cardview}" - implementation "androidx.appcompat:appcompat:${versions.appcompat}" -} diff --git a/cafebar/src/main/AndroidManifest.xml b/cafebar/src/main/AndroidManifest.xml deleted file mode 100644 index e0513a98..00000000 --- a/cafebar/src/main/AndroidManifest.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - diff --git a/cafebar/src/main/java/com/danimahardhika/cafebar/CafeBar.java b/cafebar/src/main/java/com/danimahardhika/cafebar/CafeBar.java deleted file mode 100644 index 7c376733..00000000 --- a/cafebar/src/main/java/com/danimahardhika/cafebar/CafeBar.java +++ /dev/null @@ -1,712 +0,0 @@ -package com.danimahardhika.cafebar; - -/* - * CafeBar - * - * Copyright (c) 2017 Dani Mahardhika - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import android.app.Activity; -import android.content.Context; -import android.content.res.Configuration; -import android.graphics.Bitmap; -import android.graphics.Typeface; -import android.graphics.drawable.Drawable; -import android.os.Build; -import android.text.SpannableStringBuilder; -import android.view.View; -import android.view.ViewTreeObserver; -import android.view.Window; -import android.view.WindowManager; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.google.android.material.snackbar.Snackbar; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.ref.WeakReference; -import java.util.HashMap; - -import androidx.annotation.BoolRes; -import androidx.annotation.ColorInt; -import androidx.annotation.DrawableRes; -import androidx.annotation.IntDef; -import androidx.annotation.IntRange; -import androidx.annotation.LayoutRes; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.appcompat.view.ContextThemeWrapper; -import androidx.cardview.widget.CardView; -import androidx.coordinatorlayout.widget.CoordinatorLayout; - -@SuppressWarnings("unused") -public class CafeBar { - - static final String FONT_CONTENT = "content"; - static final String FONT_POSITIVE = "positive"; - static final String FONT_NEGATIVE = "negative"; - static final String FONT_NEUTRAL = "neutral"; - - private Builder mBuilder; - private Snackbar mSnackBar; - - private CafeBar(@NonNull Builder builder) { - mBuilder = builder; - - View baseLayout = mBuilder.mCustomView; - if (baseLayout == null) { - LogUtil.d("CafeBar doesn't have customView, preparing it ..."); - baseLayout = CafeBarUtil.getBaseCafeBarView(mBuilder); - } - - mSnackBar = CafeBarUtil.getBaseSnackBar(baseLayout, mBuilder); - if (mSnackBar == null) { - mBuilder = null; - throw new IllegalStateException("CafeBar base is null"); - } - - if (mBuilder.mCustomView != null) { - LogUtil.d("CafeBar has custom view, set buttons ignored"); - return; - } - - if (mBuilder.mPositiveText == null && mBuilder.mNegativeText == null) { - //Only contains neutral button - if (mBuilder.mNeutralText != null) { - int neutralColor = CafeBarUtil.getAccentColor(mBuilder.mContext, mBuilder.mNegativeColor); - setAction(mBuilder.mNeutralText, neutralColor, mBuilder.mNeutralCallback); - } - } else { - //Contains positive or negative button - LinearLayout root = (LinearLayout) getView(); - LinearLayout buttonBase = root.findViewById(R.id.cafebar_button_base); - - if (mBuilder.mNeutralText != null) { - TextView neutral = buttonBase.findViewById(R.id.cafebar_button_neutral); - neutral.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (mBuilder.mNeutralCallback != null) { - mBuilder.mNeutralCallback.OnClick(getCafeBar()); - return; - } - - dismiss(); - } - }); - } - - if (mBuilder.mNegativeText != null) { - TextView negative = buttonBase.findViewById(R.id.cafebar_button_negative); - negative.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (mBuilder.mNegativeCallback != null) { - mBuilder.mNegativeCallback.OnClick(getCafeBar()); - return; - } - - dismiss(); - } - }); - } - - if (mBuilder.mPositiveText != null) { - TextView positive = buttonBase.findViewById(R.id.cafebar_button_positive); - positive.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (mBuilder.mPositiveCallback != null) { - mBuilder.mPositiveCallback.OnClick(getCafeBar()); - return; - } - - dismiss(); - } - }); - } - } - } - - public static void enableLogging(boolean enableLogging) { - LogUtil.sEnableLogging = enableLogging; - } - - @NonNull - public static CafeBar make(@NonNull Context context, @StringRes int res, @Snackbar.Duration int duration) { - String string = context.getResources().getString(res); - return create(context, null, string, duration); - } - - @NonNull - public static CafeBar make(@NonNull Context context, @NonNull String content, @Snackbar.Duration int duration) { - return create(context, null, content, duration); - } - - @NonNull - public static CafeBar make(@NonNull View to, @StringRes int res, @Snackbar.Duration int duration) { - Context context = to.getContext(); - if (context instanceof ContextThemeWrapper) { - context = ((ContextThemeWrapper) context).getBaseContext(); - } - String string = context.getResources().getString(res); - return create(context, to, string, duration); - } - - @NonNull - public static CafeBar make(@NonNull View to, @NonNull String content, @Snackbar.Duration int duration) { - Context context = to.getContext(); - if (context instanceof ContextThemeWrapper) { - context = ((ContextThemeWrapper) context).getBaseContext(); - } - return create(context, to, content, duration); - } - - @NonNull - private static CafeBar create(@NonNull Context context, @Nullable View to, @NonNull String content, @Snackbar.Duration int duration) { - CafeBar.Builder builder = new Builder(context); - builder.to(to); - builder.content(content); - builder.duration(duration); - if (duration == Snackbar.LENGTH_INDEFINITE) { - builder.autoDismiss(false); - } - return new CafeBar(builder); - } - - public CafeBar setAction(@StringRes int res, @Nullable CafeBarCallback callback) { - String string = mBuilder.mContext.getResources().getString(res); - int actionColor = CafeBarUtil.getAccentColor(mBuilder.mContext, mBuilder.mTheme.getTitleColor()); - setButtonAction(string, actionColor, callback); - return this; - } - - public CafeBar setAction(@NonNull String action, @Nullable CafeBarCallback callback) { - int actionColor = CafeBarUtil.getAccentColor(mBuilder.mContext, mBuilder.mTheme.getTitleColor()); - setButtonAction(action, actionColor, callback); - return this; - } - - public CafeBar setAction(@StringRes int res, int color, @Nullable CafeBarCallback callback) { - String string = mBuilder.mContext.getResources().getString(res); - setButtonAction(string, color, callback); - return this; - } - - public CafeBar setAction(@NonNull String action, int color, @Nullable CafeBarCallback callback) { - setButtonAction(action, color, callback); - return this; - } - - private void setButtonAction(@NonNull String action, int color, @Nullable final CafeBarCallback callback) { - if (mBuilder.mCustomView != null) { - LogUtil.d("CafeBar has customView, setAction ignored."); - return; - } - - LogUtil.d("preparing action view"); - mBuilder.mNeutralText = action; - mBuilder.mNeutralColor = color; - - LinearLayout root = (LinearLayout) getView(); - boolean longAction = CafeBarUtil.isLongAction(action); - - if (root.getChildCount() > 1) { - LogUtil.d("setAction already set from builder via neutralText"); - return; - } - - TextView content = root.findViewById(R.id.cafebar_content); - - int side = mBuilder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_content_padding_side); - int top = mBuilder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_content_padding_top); - int buttonPadding = mBuilder.mContext.getResources().getDimensionPixelSize( - R.dimen.cafebar_button_padding); - int bottom = 0; - - if (longAction) { - bottom = buttonPadding; - root.setOrientation(LinearLayout.VERTICAL); - content.setPadding(0, 0, buttonPadding, 0); - } else { - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) content.getLayoutParams(); - params.width = 0; - params.weight = 1f; - content.setLayoutParams(params); - } - - int navBar = 0; - if (mBuilder.mFitSystemWindow && !mBuilder.mFloating) { - navBar = CafeBarUtil.getNavigationBarHeight(mBuilder.mContext); - } - - Configuration configuration = mBuilder.mContext.getResources().getConfiguration(); - boolean tabletMode = mBuilder.mContext.getResources().getBoolean(R.bool.cafebar_tablet_mode); - - if (tabletMode || configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { - if (mBuilder.mLongContent) { - LogUtil.d("content has multi lines"); - root.setPadding(side, side, (side - buttonPadding), (side - bottom + navBar)); - } else if (longAction){ - LogUtil.d("content only 1 line with longAction"); - root.setPadding(side, top, (side - buttonPadding), (top - buttonPadding + navBar)); - } else { - LogUtil.d("content only 1 line"); - root.setPadding(side, (top - buttonPadding), (side - buttonPadding), (top - buttonPadding + navBar)); - } - } else { - if (mBuilder.mLongContent) { - LogUtil.d("content has multi lines"); - root.setPadding(side, side, (side - buttonPadding + navBar), (side - bottom)); - } else if (longAction) { - LogUtil.d("content only 1 line with longAction"); - root.setPadding(side, top, (side - buttonPadding + navBar), (top - buttonPadding)); - } else { - LogUtil.d("content only 1 line"); - root.setPadding(side, (top - buttonPadding), (side - buttonPadding + navBar), (top - buttonPadding)); - } - } - - TextView button = CafeBarUtil.getActionView(mBuilder, action, color); - if (mBuilder.getTypeface(FONT_NEUTRAL) != null) { - button.setTypeface(mBuilder.getTypeface(FONT_NEUTRAL)); - } - - if (!longAction) { - boolean multiLines = CafeBarUtil.isContentMultiLines(mBuilder); - if (multiLines) { - if (mBuilder.mFitSystemWindow && !mBuilder.mFloating) { - if (tabletMode || configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { - root.setPadding(side, side, (side - buttonPadding), (side + navBar)); - } else { - root.setPadding(side, side, (side - buttonPadding + navBar), side); - } - } else { - root.setPadding(side, side, (side - buttonPadding), side); - } - } - } - - button.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View view) { - if (callback != null) { - callback.OnClick(getCafeBar()); - return; - } - - LogUtil.d("callback = null, CafeBar dismissed"); - dismiss(); - } - }); - - root.addView(button); - } - - - - @NonNull - private CafeBar getCafeBar() { - return this; - } - - @NonNull - public View getView() { - Snackbar.SnackbarLayout snackBarLayout = (Snackbar.SnackbarLayout) mSnackBar.getView(); - - boolean tabletMode = mBuilder.mContext.getResources().getBoolean(R.bool.cafebar_tablet_mode); - - if (tabletMode || mBuilder.mFloating) { - CardView cardView = (CardView) snackBarLayout.getChildAt(0); - return cardView.getChildAt(0); - } - - LinearLayout linearLayout = (LinearLayout) snackBarLayout.getChildAt(0); - if (mBuilder.mShowShadow) return linearLayout.getChildAt(1); - return linearLayout.getChildAt(0); - } - - public void dismiss() { - if (mSnackBar == null) return; - - mSnackBar.dismiss(); - } - - public void show() { - mSnackBar.show(); - - if (mBuilder.mSwipeToDismiss) return; - - if (mSnackBar.getView().getLayoutParams() instanceof CoordinatorLayout.LayoutParams) { - mSnackBar.getView().getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { - - @Override - public boolean onPreDraw() { - mSnackBar.getView().getViewTreeObserver().removeOnPreDrawListener(this); - ((CoordinatorLayout.LayoutParams) mSnackBar.getView().getLayoutParams()).setBehavior(null); - return true; - } - }); - } - } - - @NonNull - public static Builder builder(@NonNull Context context) { - return new Builder(context); - } - - @SuppressWarnings("unused") - public static class Builder { - - Context mContext; - - @NonNull View mTo; - @Nullable View mCustomView; - CafeBarTheme.Custom mTheme = CafeBarTheme.Custom(CafeBarTheme.DARK.getColor()); - CafeBarGravity mGravity = CafeBarGravity.CENTER; - - @Snackbar.Duration - int mDuration = Snackbar.LENGTH_SHORT; - int mMaxLines = 2; - @ColorInt - int mPositiveColor = mTheme.getTitleColor(); - @ColorInt int mNegativeColor = mTheme.getTitleColor(); - @ColorInt int mNeutralColor = mTheme.getTitleColor(); - - boolean mLongContent = false; - boolean mAutoDismiss = true; - boolean mShowShadow = true; - boolean mFitSystemWindow = false; - boolean mFloating = false; - boolean mTintIcon = true; - boolean mSwipeToDismiss = true; - - private HashMap> mTypefaces; - - @Nullable Drawable mIcon = null; - - String mContent = ""; - @Nullable String mPositiveText = null; - @Nullable String mNegativeText = null; - @Nullable String mNeutralText = null; - - @Nullable SpannableStringBuilder mSpannableBuilder = null; - - @Nullable CafeBarCallback mPositiveCallback; - @Nullable CafeBarCallback mNegativeCallback; - @Nullable CafeBarCallback mNeutralCallback; - - public Builder(@NonNull Context context) { - mContext = context; - mTypefaces = new HashMap<>(); - - mTo = ((Activity) mContext).getWindow().getDecorView() - .findViewById(android.R.id.content); - } - - public Builder to(@Nullable View view) { - if (view != null) { - mTo = view; - return this; - } - - LogUtil.e("to(View): view is null, ignored"); - return this; - } - - public Builder customView(@LayoutRes int res) { - View view = View.inflate(mContext, res, null); - return customView(view); - } - - public Builder customView(@Nullable View customView) { - mCustomView = customView; - return this; - } - - public Builder content(@StringRes int res) { - return content(mContext.getResources().getString(res)); - } - - public Builder content(@NonNull String content) { - mContent = content; - return this; - } - - public Builder content(@NonNull SpannableStringBuilder spannableBuilder) { - mSpannableBuilder = spannableBuilder; - return this; - } - - public Builder maxLines(@IntRange(from = 1, to = 6) int maxLines) { - mMaxLines = maxLines; - return this; - } - - public Builder duration(@Snackbar.Duration int duration) { - mDuration = duration; - return this; - } - - public Builder theme(@NonNull CafeBarTheme theme) { - return theme(CafeBarTheme.Custom(theme.getColor())); - } - - public Builder theme(@NonNull CafeBarTheme.Custom customTheme) { - mTheme = customTheme; - mPositiveColor = mTheme.getTitleColor(); - mNegativeColor = mNeutralColor = mTheme.getSubTitleColor(); - return this; - } - - public Builder icon(@Nullable Bitmap icon) { - return icon(CafeBarUtil.toDrawable(mContext, icon), true); - } - - public Builder icon(@DrawableRes int res) { - return icon(CafeBarUtil.getDrawable(mContext, res), true); - } - - public Builder icon(@Nullable Drawable icon) { - return icon(icon, true); - } - - public Builder icon(@Nullable Bitmap icon, boolean tintIcon) { - return icon(CafeBarUtil.toDrawable(mContext, icon), tintIcon); - } - - public Builder icon(@DrawableRes int res, boolean tintIcon) { - return icon(CafeBarUtil.getDrawable(mContext, res), tintIcon); - } - - public Builder icon(@Nullable Drawable icon, boolean tintIcon) { - mIcon = icon; - mTintIcon = tintIcon; - return this; - } - - public Builder showShadow(@BoolRes int res) { - return showShadow(mContext.getResources().getBoolean(res)); - } - - public Builder showShadow(boolean showShadow) { - mShowShadow = showShadow; - return this; - } - - public Builder autoDismiss(@BoolRes int res) { - return autoDismiss(mContext.getResources().getBoolean(res)); - } - - public Builder autoDismiss(boolean autoDismiss) { - mAutoDismiss = autoDismiss; - return this; - } - - public Builder swipeToDismiss(@BoolRes int res) { - return swipeToDismiss(mContext.getResources().getBoolean(res)); - } - - public Builder swipeToDismiss(boolean swipeToDismiss) { - mSwipeToDismiss = swipeToDismiss; - return this; - } - - public Builder floating(@BoolRes int res) { - return floating(mContext.getResources().getBoolean(res)); - } - - public Builder floating(boolean floating) { - mFloating = floating; - return this; - } - - public Builder gravity(@NonNull CafeBarGravity gravity) { - mGravity = gravity; - return this; - } - - public Builder fitSystemWindow() { - Activity activity = (Activity) mContext; - Window window = activity.getWindow(); - if (window == null) { - LogUtil.d("fitSystemWindow() window is null"); - return this; - } - - WindowManager.LayoutParams params = window.getAttributes(); - int navigationBarHeight = CafeBarUtil.getNavigationBarHeight(mContext); - - boolean isInMultiWindowMode = false; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - isInMultiWindowMode = activity.isInMultiWindowMode(); - } - - if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == - WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) { - mFitSystemWindow = navigationBarHeight > 0 && !isInMultiWindowMode; - } - return this; - } - - public Builder typeface(String contentFontName, String buttonFontName) { - return typeface(CafeBarUtil.getTypeface(mContext, contentFontName), - CafeBarUtil.getTypeface(mContext, buttonFontName)); - } - - public Builder typeface(@Nullable Typeface content, @Nullable Typeface button) { - addTypeface(FONT_CONTENT, content); - addTypeface(FONT_POSITIVE, button); - addTypeface(FONT_NEGATIVE, button); - addTypeface(FONT_NEUTRAL, button); - return this; - } - - public Builder contentTypeface(String fontName) { - return contentTypeface(CafeBarUtil.getTypeface(mContext, fontName)); - } - - public Builder contentTypeface(@Nullable Typeface typeface) { - addTypeface(FONT_CONTENT, typeface); - return this; - } - - public Builder positiveTypeface(String fontName) { - return positiveTypeface(CafeBarUtil.getTypeface(mContext, fontName)); - } - - public Builder positiveTypeface(@Nullable Typeface typeface) { - addTypeface(FONT_POSITIVE,typeface); - return this; - } - - public Builder negativeTypeface(String fontName) { - return negativeTypeface(CafeBarUtil.getTypeface(mContext, fontName)); - } - - public Builder negativeTypeface(@Nullable Typeface typeface) { - addTypeface(FONT_NEGATIVE, typeface); - return this; - } - - public Builder neutralTypeface(String fontName) { - return neutralTypeface(CafeBarUtil.getTypeface(mContext, fontName)); - } - - public Builder neutralTypeface(@Nullable Typeface typeface) { - addTypeface(FONT_NEUTRAL, typeface); - return this; - } - - public Builder buttonTypeface(String fontName) { - return buttonTypeface(CafeBarUtil.getTypeface(mContext, fontName)); - } - - public Builder buttonTypeface(@Nullable Typeface typeface) { - addTypeface(FONT_POSITIVE, typeface); - addTypeface(FONT_NEGATIVE, typeface); - addTypeface(FONT_NEUTRAL, typeface); - return this; - } - - public Builder positiveColor(int positiveColor) { - mPositiveColor = CafeBarUtil.getColor(mContext, positiveColor); - return this; - } - - public Builder negativeColor(int negativeColor) { - mNegativeColor = CafeBarUtil.getColor(mContext, negativeColor); - return this; - } - - public Builder neutralColor(int neutralColor) { - mNeutralColor = CafeBarUtil.getColor(mContext, neutralColor); - return this; - } - - public Builder buttonColor(int buttonColor) { - int color = CafeBarUtil.getColor(mContext, buttonColor); - mNeutralColor = mPositiveColor = mNegativeColor = color; - return this; - } - - public Builder positiveText(@StringRes int res) { - return positiveText(mContext.getResources().getString(res)); - } - - public Builder positiveText(@NonNull String positiveText) { - mPositiveText = positiveText; - return this; - } - - public Builder negativeText(@StringRes int res) { - return negativeText(mContext.getResources().getString(res)); - } - - public Builder negativeText(@NonNull String negativeText) { - mNegativeText = negativeText; - return this; - } - - public Builder neutralText(@StringRes int res) { - return neutralText(mContext.getResources().getString(res)); - } - - public Builder neutralText(@NonNull String neutralText) { - mNeutralText = neutralText; - return this; - } - - public Builder onPositive(@Nullable CafeBarCallback positiveCallback) { - mPositiveCallback = positiveCallback; - return this; - } - - public Builder onNegative(@Nullable CafeBarCallback negativeCallback) { - mNegativeCallback = negativeCallback; - return this; - } - - public Builder onNeutral(@Nullable CafeBarCallback neutralCallback) { - mNeutralCallback = neutralCallback; - return this; - } - - public CafeBar build() { - return new CafeBar(this); - } - - public void show() { - build().show(); - } - - private void addTypeface(String name, Typeface typeface) { - if (!mTypefaces.containsKey(name) || mTypefaces.get(name) == null) { - mTypefaces.put(name, new WeakReference<>(typeface)); - } - } - - @Nullable - Typeface getTypeface(String name) { - if (mTypefaces.get(name) != null) { - return mTypefaces.get(name).get(); - } - return null; - } - } -} diff --git a/cafebar/src/main/java/com/danimahardhika/cafebar/CafeBarCallback.java b/cafebar/src/main/java/com/danimahardhika/cafebar/CafeBarCallback.java deleted file mode 100644 index 4a25749a..00000000 --- a/cafebar/src/main/java/com/danimahardhika/cafebar/CafeBarCallback.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.danimahardhika.cafebar; - -/* - * CafeBar - * - * Copyright (c) 2017 Dani Mahardhika - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -import androidx.annotation.NonNull; - -public interface CafeBarCallback { - - void OnClick(@NonNull CafeBar cafeBar); -} diff --git a/cafebar/src/main/java/com/danimahardhika/cafebar/CafeBarGravity.java b/cafebar/src/main/java/com/danimahardhika/cafebar/CafeBarGravity.java deleted file mode 100644 index 9cd17023..00000000 --- a/cafebar/src/main/java/com/danimahardhika/cafebar/CafeBarGravity.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.danimahardhika.cafebar; - -/* - * CafeBar - * - * Copyright (c) 2017 Dani Mahardhika - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -import android.view.Gravity; - -@SuppressWarnings("unused") -public enum CafeBarGravity { - START(Gravity.START), - CENTER(Gravity.CENTER), - END(Gravity.END); - - private int mGravity; - - CafeBarGravity(int gravity) { - mGravity = gravity; - } - - int getGravity() { - return mGravity; - } -} diff --git a/cafebar/src/main/java/com/danimahardhika/cafebar/CafeBarTheme.java b/cafebar/src/main/java/com/danimahardhika/cafebar/CafeBarTheme.java deleted file mode 100644 index 2ec8f3c8..00000000 --- a/cafebar/src/main/java/com/danimahardhika/cafebar/CafeBarTheme.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.danimahardhika.cafebar; - -/* - * CafeBar - * - * Copyright (c) 2017 Dani Mahardhika - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import android.graphics.Color; - -import androidx.annotation.ColorInt; - -@SuppressWarnings("unused") -public enum CafeBarTheme { - - LIGHT(Color.parseColor("#F5F5F5")), - DARK(Color.parseColor("#323232")), - CLEAR_BLACK(Color.BLACK); - - private int mColor; - - CafeBarTheme(@ColorInt int color) { - mColor = color; - } - - @ColorInt - int getColor() { - return mColor; - } - - public static Custom Custom(@ColorInt int color) { - return new Custom(color); - } - - public static class Custom { - - private int mColor; - - private Custom(int color) { - mColor = color; - } - - @ColorInt - int getColor() { - return mColor; - } - - @ColorInt - int getTitleColor() { - return CafeBarUtil.getTitleTextColor(mColor); - } - - @ColorInt - int getSubTitleColor() { - return CafeBarUtil.getSubTitleTextColor(mColor); - } - } -} diff --git a/cafebar/src/main/java/com/danimahardhika/cafebar/CafeBarUtil.java b/cafebar/src/main/java/com/danimahardhika/cafebar/CafeBarUtil.java deleted file mode 100644 index 7a776342..00000000 --- a/cafebar/src/main/java/com/danimahardhika/cafebar/CafeBarUtil.java +++ /dev/null @@ -1,593 +0,0 @@ -package com.danimahardhika.cafebar; - -/* - * CafeBar - * - * Copyright (c) 2017 Dani Mahardhika - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -import android.app.Activity; -import android.content.Context; -import android.content.res.Configuration; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Point; -import android.graphics.PorterDuff; -import android.graphics.Typeface; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.os.Build; -import android.text.TextUtils; -import android.util.DisplayMetrics; -import android.util.Log; -import android.util.TypedValue; -import android.view.Display; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.view.WindowManager; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.google.android.material.snackbar.Snackbar; - -import java.util.Locale; - -import androidx.annotation.ColorInt; -import androidx.annotation.DrawableRes; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.cardview.widget.CardView; -import androidx.core.content.ContextCompat; - -class CafeBarUtil { - - @NonNull - static View getBaseCafeBarView(@NonNull CafeBar.Builder builder) { - int color = builder.mTheme.getColor(); - int titleColor = builder.mTheme.getTitleColor(); - - //Creating LinearLayout as rootView - LinearLayout root = new LinearLayout(builder.mContext); - root.setId(R.id.cafebar_root); - root.setOrientation(LinearLayout.HORIZONTAL); - root.setGravity(Gravity.CENTER_VERTICAL); - root.setBackgroundColor(color); - root.setLayoutParams(new LinearLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT)); - root.setClickable(true); - - //Creating TextView for content - TextView content = new TextView(builder.mContext); - content.setId(R.id.cafebar_content); - content.setMaxLines(builder.mMaxLines); - content.setEllipsize(TextUtils.TruncateAt.END); - content.setTextColor(titleColor); - content.setTextSize(TypedValue.COMPLEX_UNIT_PX, builder.mContext.getResources() - .getDimensionPixelSize(R.dimen.cafebar_content_text)); - if (builder.getTypeface(CafeBar.FONT_CONTENT) != null) { - content.setTypeface(builder.getTypeface(CafeBar.FONT_CONTENT)); - } - - content.setText(builder.mContent); - if (builder.mSpannableBuilder != null) { - content.setText(builder.mSpannableBuilder, TextView.BufferType.SPANNABLE); - } - - content.setLayoutParams(new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT)); - content.setGravity(Gravity.CENTER_VERTICAL); - - boolean tabletMode = builder.mContext.getResources().getBoolean(R.bool.cafebar_tablet_mode); - if (tabletMode || builder.mFloating) { - content.setLayoutParams(new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.WRAP_CONTENT, - LinearLayout.LayoutParams.WRAP_CONTENT)); - content.setMinWidth(builder.mContext.getResources() - .getDimensionPixelSize(R.dimen.cafebar_floating_min_width)); - content.setMaxWidth(builder.mContext.getResources() - .getDimensionPixelSize(R.dimen.cafebar_floating_max_width)); - } - - int side = builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_content_padding_side); - int top = builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_content_padding_top); - - if (builder.mIcon != null) { - Drawable drawable = getResizedDrawable( - builder.mContext, - builder.mIcon, - titleColor, - builder.mTintIcon); - if (drawable != null) { - content.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); - content.setCompoundDrawablePadding(top); - } - } - - boolean multiLines = isContentMultiLines(builder); - boolean containsPositive = builder.mPositiveText != null; - boolean containsNegative = builder.mNegativeText != null; - boolean longNeutralAction = isLongAction(builder.mNeutralText); - - if (multiLines || containsPositive || containsNegative || longNeutralAction) { - top = side; - builder.mLongContent = true; - } - - root.setPadding(side, top, side, top); - - if (builder.mPositiveText == null && builder.mNegativeText == null) { - if (builder.mFitSystemWindow && !builder.mFloating) { - Configuration configuration = builder.mContext.getResources().getConfiguration(); - int navBar = getNavigationBarHeight(builder.mContext); - - if (tabletMode || configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { - root.setPadding(side, top, side, (top + navBar)); - } else { - root.setPadding(side, top, (side + navBar), top); - } - } - - //Adding childView to rootView - root.addView(content); - - //Returning rootView - return root; - } - - //Change root orientation to vertical - root.setOrientation(LinearLayout.VERTICAL); - - //Creating another linear layout for button container - LinearLayout buttonBase = new LinearLayout(builder.mContext); - buttonBase.setId(R.id.cafebar_button_base); - buttonBase.setOrientation(LinearLayout.HORIZONTAL); - buttonBase.setGravity(Gravity.END); - buttonBase.setLayoutParams(new LinearLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT)); - - //Adding button - String neutralText = builder.mNeutralText; - if (neutralText != null) { - TextView neutral = getActionView(builder, neutralText, builder.mNeutralColor); - neutral.setId(R.id.cafebar_button_neutral); - - if (builder.getTypeface(CafeBar.FONT_NEUTRAL) != null) { - neutral.setTypeface(builder.getTypeface(CafeBar.FONT_NEUTRAL)); - } - - buttonBase.addView(neutral); - } - - String negativeText = builder.mNegativeText; - if (negativeText != null) { - TextView negative = getActionView(builder, negativeText, builder.mNegativeColor); - negative.setId(R.id.cafebar_button_negative); - - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) negative.getLayoutParams(); - params.setMargins( - params.leftMargin + builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_button_margin), - params.topMargin, - params.rightMargin, - params.bottomMargin); - - if (builder.getTypeface(CafeBar.FONT_NEGATIVE) != null) { - negative.setTypeface(builder.getTypeface(CafeBar.FONT_NEGATIVE)); - } - - buttonBase.addView(negative); - } - - String positiveText = builder.mPositiveText; - if (positiveText != null) { - int positiveColor = CafeBarUtil.getAccentColor(builder.mContext, builder.mPositiveColor); - TextView positive = getActionView(builder, positiveText, positiveColor); - positive.setId(R.id.cafebar_button_positive); - - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) positive.getLayoutParams(); - params.setMargins( - params.leftMargin + builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_button_margin), - params.topMargin, - params.rightMargin, - params.bottomMargin); - - if (builder.getTypeface(CafeBar.FONT_POSITIVE) != null) { - positive.setTypeface(builder.getTypeface(CafeBar.FONT_POSITIVE)); - } - - buttonBase.addView(positive); - } - - //Adjust padding - int buttonPadding = builder.mContext.getResources().getDimensionPixelSize( - R.dimen.cafebar_button_padding); - root.setPadding(side, top, (side - buttonPadding), (top - buttonPadding)); - - if (builder.mFitSystemWindow && !builder.mFloating) { - Configuration configuration = builder.mContext.getResources().getConfiguration(); - int navBar = getNavigationBarHeight(builder.mContext); - - if (tabletMode || configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { - root.setPadding(side, top, (side - buttonPadding), (top - buttonPadding + navBar)); - } else { - root.setPadding(side, top, (side - buttonPadding + navBar), top); - } - } - - //Adding content to container - content.setPadding(0, 0, buttonPadding, 0); - - //Adding childView to rootView - root.addView(content); - - //Adding button container to root - root.addView(buttonBase); - - //Returning rootView - return root; - } - - static Snackbar getBaseSnackBar(@NonNull View cafeBarLayout, - @NonNull CafeBar.Builder builder) { - View view = builder.mTo; - - Snackbar snackBar = Snackbar.make(view, "", builder.mAutoDismiss ? - builder.mDuration : Snackbar.LENGTH_INDEFINITE); - Snackbar.SnackbarLayout snackBarLayout = (Snackbar.SnackbarLayout) snackBar.getView(); - snackBarLayout.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT; - snackBarLayout.setPadding(0, 0, 0, 0); - snackBarLayout.setBackgroundColor(Color.TRANSPARENT); - snackBarLayout.setClickable(false); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - snackBarLayout.setElevation(0); - } - - TextView textView = snackBarLayout.findViewById( - R.id.snackbar_text); - if (textView != null) textView.setVisibility(View.INVISIBLE); - - boolean tabletMode = builder.mContext.getResources().getBoolean(R.bool.cafebar_tablet_mode); - if (tabletMode || builder.mFloating) { - int shadow = builder.mContext.getResources().getDimensionPixelSize(R.dimen.cardview_default_elevation); - int padding = builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_floating_padding); - - CardView cardView = new CardView(builder.mContext); - cardView.setUseCompatPadding(false); - Snackbar.SnackbarLayout.LayoutParams params = new Snackbar.SnackbarLayout.LayoutParams( - LinearLayout.LayoutParams.WRAP_CONTENT, - LinearLayout.LayoutParams.WRAP_CONTENT); - params.gravity = builder.mGravity.getGravity(); - - int bottom = builder.mFloating ? padding : 0; - snackBarLayout.setClipToPadding(false); - snackBarLayout.setPadding(padding, shadow, padding, bottom); - - if (builder.mFitSystemWindow && builder.mFloating) { - Configuration configuration = builder.mContext.getResources().getConfiguration(); - int navBar = getNavigationBarHeight(builder.mContext); - - if (configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { - snackBarLayout.setPadding(padding, shadow, padding, bottom + navBar); - } else { - snackBarLayout.setPadding(padding, shadow, padding + navBar, bottom); - } - } - - cardView.setLayoutParams(params); - cardView.setClickable(true); - if (!builder.mShowShadow) { - cardView.setCardElevation(0f); - } - - cardView.addView(cafeBarLayout); - snackBarLayout.addView(cardView, 0); - return snackBar; - } - - LinearLayout root = new LinearLayout(builder.mContext); - root.setOrientation(LinearLayout.VERTICAL); - root.setLayoutParams(new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT)); - - if (builder.mShowShadow) { - View shadow = new View(builder.mContext); - shadow.setLayoutParams(new LinearLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - builder.mContext.getResources().getDimensionPixelSize( - R.dimen.cafebar_shadow_top))); - shadow.setBackgroundResource(R.drawable.cafebar_shadow_top); - root.addView(shadow); - } - - root.addView(cafeBarLayout); - snackBarLayout.addView(root, 0); - return snackBar; - } - - @NonNull - static TextView getActionView(@NonNull CafeBar.Builder builder, @NonNull String action, int color) { - boolean longAction = isLongAction(action); - int res = R.layout.cafebar_action_button_dark; - - CafeBarTheme.Custom customTheme = builder.mTheme; - int titleColor = customTheme.getTitleColor(); - boolean dark = titleColor != Color.WHITE; - if (dark) { - res = R.layout.cafebar_action_button; - } - - int padding = builder.mContext.getResources().getDimensionPixelSize( - R.dimen.cafebar_button_padding); - - TextView button = (TextView) View.inflate(builder.mContext, res, null); - button.setText(action.toUpperCase(Locale.getDefault())); - button.setMaxLines(1); - button.setEllipsize(TextUtils.TruncateAt.END); - button.setTextColor(color); - button.setPadding(padding, padding, padding, padding); - - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.WRAP_CONTENT, - LinearLayout.LayoutParams.WRAP_CONTENT); - - int side = builder.mContext.getResources().getDimensionPixelSize( - R.dimen.cafebar_content_padding_side); - int margin = builder.mContext.getResources().getDimensionPixelSize( - R.dimen.cafebar_button_margin_start); - params.setMargins(margin, 0, 0, 0); - - if (longAction) { - params.setMargins(0, (side - padding), 0, 0); - } - - if (builder.mPositiveText != null || builder.mNegativeText != null) { - longAction = true; - params.setMargins(0, (side - padding), 0, 0); - } else { - params.gravity = Gravity.CENTER_VERTICAL | Gravity.END; - } - - button.setLayoutParams(params); - - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - button.setBackgroundResource(dark ? R.drawable.cafebar_action_button_selector_dark : - R.drawable.cafebar_action_button_selector); - return button; - } - - TypedValue outValue = new TypedValue(); - builder.mContext.getTheme().resolveAttribute(longAction ? - R.attr.selectableItemBackground : R.attr.selectableItemBackgroundBorderless, - outValue, true); - button.setBackgroundResource(outValue.resourceId); - return button; - } - - static boolean isContentMultiLines(@NonNull CafeBar.Builder builder) { - DisplayMetrics metrics = new DisplayMetrics(); - ((Activity) builder.mContext).getWindowManager().getDefaultDisplay().getMetrics(metrics); - - boolean tabletMode = builder.mContext.getResources().getBoolean(R.bool.cafebar_tablet_mode); - int padding = (builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_content_padding_side) * 2); - - if (builder.mNeutralText != null && builder.mNegativeText == null && builder.mPositiveText == null && - !isLongAction(builder.mNeutralText)) { - padding += builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_button_margin_start); - - int actionPadding = builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_button_padding); - TextView action = new TextView(builder.mContext); - action.setTextSize(TypedValue.COMPLEX_UNIT_PX, builder.mContext.getResources() - .getDimensionPixelSize(R.dimen.cafebar_content_text)); - if (builder.getTypeface(CafeBar.FONT_NEUTRAL) != null) { - action.setTypeface(builder.getTypeface(CafeBar.FONT_CONTENT)); - } - action.setPadding(actionPadding, 0, actionPadding, 0); - action.setText(builder.mNeutralText.substring(0, - builder.mNeutralText.length() > 10 ? 10 : builder.mNeutralText.length())); - - int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(metrics.widthPixels, View.MeasureSpec.AT_MOST); - int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); - action.measure(widthMeasureSpec, heightMeasureSpec); - - LogUtil.d("measured action width: " +action.getMeasuredWidth()); - padding += action.getMeasuredWidth(); - } - - if (builder.mIcon != null) { - int icon = builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_icon_size); - icon += builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_content_padding_top); - padding += icon; - } - - TextView textView = new TextView(builder.mContext); - textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, builder.mContext.getResources() - .getDimension(R.dimen.cafebar_content_text)); - textView.setPadding(padding, 0, 0, 0); - if (builder.getTypeface(CafeBar.FONT_CONTENT) != null) { - textView.setTypeface(builder.getTypeface(CafeBar.FONT_CONTENT)); - } - - if (builder.mSpannableBuilder != null) { - textView.setText(builder.mSpannableBuilder, TextView.BufferType.SPANNABLE); - } else { - textView.setText(builder.mContent); - } - - int maxWidth = metrics.widthPixels; - if (builder.mFloating || tabletMode) { - maxWidth = builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_floating_max_width); - } - - int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(maxWidth, View.MeasureSpec.AT_MOST); - int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); - textView.measure(widthMeasureSpec, heightMeasureSpec); - return textView.getLineCount() > 1; - } - - @Nullable - static Drawable getDrawable(@NonNull Context context, @DrawableRes int res) { - try { - Drawable drawable = context.getResources().getDrawable(res); - return drawable.mutate(); - } catch (OutOfMemoryError e) { - return null; - } - } - - @Nullable - static Drawable toDrawable(@NonNull Context context, @Nullable Bitmap bitmap) { - try { - if (bitmap == null) return null; - return new BitmapDrawable(context.getResources(), bitmap); - } catch (OutOfMemoryError e) { - return null; - } - } - - @Nullable - private static Drawable getResizedDrawable(@NonNull Context context, @Nullable Drawable drawable, - int color, boolean tint) { - try { - if (drawable == null) { - LogUtil.d("drawable: null"); - return null; - } - - if (tint) { - drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN); - drawable.mutate(); - } - - int size = context.getResources().getDimensionPixelSize(R.dimen.cafebar_icon_size); - Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), - drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); - drawable.draw(canvas); - - return new BitmapDrawable(context.getResources(), - Bitmap.createScaledBitmap(bitmap, size, size, true)); - } catch (Exception | OutOfMemoryError e) { - LogUtil.e(Log.getStackTraceString(e)); - return null; - } - } - - static int getNavigationBarHeight(@NonNull Context context) { - Point appUsableSize = getAppUsableScreenSize(context); - Point realScreenSize = getRealScreenSize(context); - - if (appUsableSize.x < realScreenSize.x) { - Point point = new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y); - return point.x; - } - - if (appUsableSize.y < realScreenSize.y) { - Point point = new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y); - return point.y; - } - return 0; - } - - private static Point getAppUsableScreenSize(@NonNull Context context) { - WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); - Display display = windowManager.getDefaultDisplay(); - Point size = new Point(); - display.getSize(size); - return size; - } - - private static Point getRealScreenSize(@NonNull Context context) { - WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); - Display display = windowManager.getDefaultDisplay(); - Point size = new Point(); - - if (Build.VERSION.SDK_INT >= 17) { - display.getRealSize(size); - } else if (Build.VERSION.SDK_INT >= 14) { - try { - size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display); - size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display); - } catch (Exception e) { - LogUtil.e(Log.getStackTraceString(e)); - } - } - return size; - } - - static boolean isLongAction(@Nullable String action) { - return action != null && action.length() > 10; - } - - static int getAccentColor(Context context, int defaultColor) { - if (context == null) { - LogUtil.e("getAccentColor() context is null"); - return defaultColor; - } - - TypedValue typedValue = new TypedValue(); - Resources.Theme theme = context.getTheme(); - theme.resolveAttribute(R.attr.colorAccent, typedValue, true); - return typedValue.data; - } - - static int getTitleTextColor(@ColorInt int color) { - double darkness = 1-(0.299*Color.red(color) + 0.587*Color.green(color) + 0.114*Color.blue(color))/255; - return (darkness < 0.35) ? getDarkerColor(color) : Color.WHITE; - } - - static int getSubTitleTextColor(@ColorInt int color) { - int titleColor = getTitleTextColor(color); - int alpha2 = Math.round(Color.alpha(titleColor) * 0.7f); - int red = Color.red(titleColor); - int green = Color.green(titleColor); - int blue = Color.blue(titleColor); - return Color.argb(alpha2, red, green, blue); - } - - private static int getDarkerColor(@ColorInt int color) { - float[] hsv = new float[3]; - Color.colorToHSV(color, hsv); - hsv[2] *= 0.25f; - return Color.HSVToColor(hsv); - } - - static int getColor(@NonNull Context context, int color) { - try { - return ContextCompat.getColor(context, color); - } catch (Exception e) { - LogUtil.e(Log.getStackTraceString(e)); - return color; - } - } - - @Nullable - static Typeface getTypeface(@NonNull Context context, String fontName) { - try { - return Typeface.createFromAsset(context.getAssets(), "fonts/" +fontName); - } catch (Exception e) { - LogUtil.e(Log.getStackTraceString(e)); - } - return null; - } -} diff --git a/cafebar/src/main/java/com/danimahardhika/cafebar/LogUtil.java b/cafebar/src/main/java/com/danimahardhika/cafebar/LogUtil.java deleted file mode 100644 index 6a0aad64..00000000 --- a/cafebar/src/main/java/com/danimahardhika/cafebar/LogUtil.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.danimahardhika.cafebar; - -/* - * CafeBar - * - * Copyright (c) 2017 Dani Mahardhika - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import android.util.Log; - -import androidx.annotation.NonNull; - -class LogUtil { - - static boolean sEnableLogging = false; - - private static final String TAG = "CafeBar"; - - static void d(@NonNull String message) { - if (LogUtil.sEnableLogging) - Log.d(TAG, message); - } - - static void e(@NonNull String message) { - if (LogUtil.sEnableLogging) - Log.e(TAG, message); - } -} diff --git a/cafebar/src/main/res-public/values/public.xml b/cafebar/src/main/res-public/values/public.xml deleted file mode 100644 index 4705295e..00000000 --- a/cafebar/src/main/res-public/values/public.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/cafebar/src/main/res/drawable/cafebar_action_button_selector.xml b/cafebar/src/main/res/drawable/cafebar_action_button_selector.xml deleted file mode 100644 index ebca92b2..00000000 --- a/cafebar/src/main/res/drawable/cafebar_action_button_selector.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/cafebar/src/main/res/drawable/cafebar_action_button_selector_dark.xml b/cafebar/src/main/res/drawable/cafebar_action_button_selector_dark.xml deleted file mode 100644 index 075d3975..00000000 --- a/cafebar/src/main/res/drawable/cafebar_action_button_selector_dark.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/cafebar/src/main/res/drawable/cafebar_shadow_top.xml b/cafebar/src/main/res/drawable/cafebar_shadow_top.xml deleted file mode 100644 index eb6c9068..00000000 --- a/cafebar/src/main/res/drawable/cafebar_shadow_top.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/cafebar/src/main/res/layout/cafebar_action_button.xml b/cafebar/src/main/res/layout/cafebar_action_button.xml deleted file mode 100644 index 6f21978d..00000000 --- a/cafebar/src/main/res/layout/cafebar_action_button.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - \ No newline at end of file diff --git a/cafebar/src/main/res/layout/cafebar_action_button_dark.xml b/cafebar/src/main/res/layout/cafebar_action_button_dark.xml deleted file mode 100644 index 888a548d..00000000 --- a/cafebar/src/main/res/layout/cafebar_action_button_dark.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - \ No newline at end of file diff --git a/cafebar/src/main/res/values-sw600dp-land/dimens.xml b/cafebar/src/main/res/values-sw600dp-land/dimens.xml deleted file mode 100644 index 5799a6b2..00000000 --- a/cafebar/src/main/res/values-sw600dp-land/dimens.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - 288dp - - \ No newline at end of file diff --git a/cafebar/src/main/res/values-sw600dp/bools.xml b/cafebar/src/main/res/values-sw600dp/bools.xml deleted file mode 100644 index c203d3be..00000000 --- a/cafebar/src/main/res/values-sw600dp/bools.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - true - - \ No newline at end of file diff --git a/cafebar/src/main/res/values-sw600dp/dimens.xml b/cafebar/src/main/res/values-sw600dp/dimens.xml deleted file mode 100644 index a9a49daf..00000000 --- a/cafebar/src/main/res/values-sw600dp/dimens.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - 48dp - - - 188dp - 568dp - 24dp - - \ No newline at end of file diff --git a/cafebar/src/main/res/values/bools.xml b/cafebar/src/main/res/values/bools.xml deleted file mode 100644 index 944cf2a0..00000000 --- a/cafebar/src/main/res/values/bools.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - false - - \ No newline at end of file diff --git a/cafebar/src/main/res/values/colors.xml b/cafebar/src/main/res/values/colors.xml deleted file mode 100644 index eac88795..00000000 --- a/cafebar/src/main/res/values/colors.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - #44000000 - #44FFFFFF - - \ No newline at end of file diff --git a/cafebar/src/main/res/values/dimens.xml b/cafebar/src/main/res/values/dimens.xml deleted file mode 100644 index 6082bac0..00000000 --- a/cafebar/src/main/res/values/dimens.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - 24dp - - 24dp - 14dp - - 24dp - 10dp - 8dp - - 4dp - 14sp - - - 108dp - 368dp - 16dp - - \ No newline at end of file diff --git a/cafebar/src/main/res/values/ids.xml b/cafebar/src/main/res/values/ids.xml deleted file mode 100644 index c5bb9f24..00000000 --- a/cafebar/src/main/res/values/ids.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/cafebar/src/main/res/values/styles.xml b/cafebar/src/main/res/values/styles.xml deleted file mode 100644 index 2d8c8ae4..00000000 --- a/cafebar/src/main/res/values/styles.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/codegen/.gitignore b/codegen/.gitignore deleted file mode 100644 index 796b96d1..00000000 --- a/codegen/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/codegen/build.gradle b/codegen/build.gradle deleted file mode 100644 index e2630bd0..00000000 --- a/codegen/build.gradle +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) Kuba Szczodrzyński 2020-3-28. - */ - -apply plugin: 'java-library' -apply plugin: 'kotlin' -apply plugin: 'kotlin-kapt' - -kapt { - generateStubs = true -} - -sourceSets { - main { - java { - srcDir "${buildDir.absolutePath}/tmp/kapt/main/kotlinGenerated/" - } - } -} - - -dependencies { - kapt project(":annotation") - compileOnly project(':annotation') - implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - - // configuration generator for service providers - implementation "com.google.auto.service:auto-service:1.0-rc4" - kapt "com.google.auto.service:auto-service:1.0-rc4" - kapt "androidx.room:room-compiler:${versions.room}" - implementation "androidx.room:room-runtime:${versions.room}" - implementation "com.squareup:kotlinpoet:1.5.0" - implementation "androidx.sqlite:sqlite:2.1.0@aar" - -} - -sourceCompatibility = "7" -targetCompatibility = "7" diff --git a/codegen/src/main/java/pl/szczodrzynski/edziennik/codegen/FileGenerator.kt b/codegen/src/main/java/pl/szczodrzynski/edziennik/codegen/FileGenerator.kt deleted file mode 100644 index 5b5b1f71..00000000 --- a/codegen/src/main/java/pl/szczodrzynski/edziennik/codegen/FileGenerator.kt +++ /dev/null @@ -1,342 +0,0 @@ -/* - * Copyright (c) Kuba Szczodrzyński 2020-3-28. - */ - -package pl.szczodrzynski.edziennik.codegen - -import androidx.room.ColumnInfo -import androidx.room.Entity -import androidx.room.Ignore -import androidx.room.TypeConverters -import com.google.auto.service.AutoService -import com.squareup.kotlinpoet.* -import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import pl.szczodrzynski.edziennik.annotation.SelectiveDao -import pl.szczodrzynski.edziennik.annotation.UpdateSelective -import java.io.File -import javax.annotation.processing.* -import javax.lang.model.SourceVersion -import javax.lang.model.element.* -import javax.lang.model.type.* -import javax.lang.model.util.ElementFilter -import javax.tools.Diagnostic -import kotlin.reflect.KClass - -@Suppress("unused") -@AutoService(Processor::class) -@SupportedSourceVersion(SourceVersion.RELEASE_8) -@SupportedOptions(FileGenerator.KAPT_KOTLIN_GENERATED_OPTION_NAME) -class FileGenerator : AbstractProcessor() { - companion object { - const val KAPT_KOTLIN_GENERATED_OPTION_NAME = "kapt.kotlin.generated" - } - - private data class TypeConverter(val dataType: TypeMirror, val converterType: TypeElement, val methodName: Name, val returnType: TypeMirror) - - private inline fun Element.getAnnotationClassValue(f: T.() -> KClass<*>) = try { - getAnnotation(T::class.java).f() - throw Exception("Expected to get a MirroredTypeException") - } catch (e: MirroredTypeException) { - e.typeMirror - } - private inline fun Element.getAnnotationClassValues(f: T.() -> Array>) = try { - getAnnotation(T::class.java).f() - throw Exception("Expected to get a MirroredTypesException") - } catch (e: MirroredTypesException) { - e.typeMirrors - } - - override fun process(set: MutableSet?, roundEnvironment: RoundEnvironment?): Boolean { - roundEnvironment?.getElementsAnnotatedWith(SelectiveDao::class.java)?.forEach { it -> - if (it.kind != ElementKind.CLASS) { - processingEnv.messager.printMessage(Diagnostic.Kind.ERROR, "Can only be applied to classes, element: $it") - return false - } - - val generatedSourcesRoot = processingEnv.options[KAPT_KOTLIN_GENERATED_OPTION_NAME] - if (generatedSourcesRoot?.isEmpty() != false) { - processingEnv.messager.printMessage(Diagnostic.Kind.ERROR, "Can't find the target directory for generated Kotlin files.") - return false - } - - val file = File(generatedSourcesRoot) - file.mkdirs() - - val dao = it as TypeElement - processClass(dao, file) - - //processingEnv.messager.printMessage(Diagnostic.Kind.ERROR, "package = $packageName, className = $className, methodName = $methodName, tableName = $tableName, paramName = $paramName, paramClass = $paramClass") - } - return true - } - - private fun processClass(dao: TypeElement, file: File) { - val daoName = dao.simpleName.toString() - val packageName = processingEnv.elementUtils.getPackageOf(dao).toString() - - val dbType = processingEnv.typeUtils.asElement(dao.getAnnotationClassValue { db }) as TypeElement - val typeConverters = dbType.getAnnotationClassValues { value }.map { - processingEnv.typeUtils.asElement(it) as TypeElement - }.map { type -> - processingEnv.elementUtils.getAllMembers(type).mapNotNull { element -> - if (element is ExecutableElement) { - if (element.returnType.toString() == "java.lang.String" - || element.returnType.toString() == "java.lang.Long" - || element.returnType.toString() == "java.lang.Integer" - || element.returnType.kind.isPrimitive) { - if (element.simpleName.startsWith("to") && element.parameters.isNotEmpty()) - return@mapNotNull TypeConverter(element.parameters.first().asType(), type, element.simpleName, element.returnType) - } - } - null - } - }.flatten() - - //processingEnv.messager.printMessage(Diagnostic.Kind.ERROR, "c = ${typeConverters.joinToString()}") - - val roomDatabase = ClassName("androidx.room", "RoomDatabase") - val selective = TypeSpec.classBuilder("${daoName}Selective") - .primaryConstructor(FunSpec.constructorBuilder() - .addParameter("__db", roomDatabase, KModifier.PRIVATE) - .build()) - .addProperty(PropertySpec.builder("__db", roomDatabase) - .initializer("__db") - .addModifiers(KModifier.PRIVATE) - .build()) - - val usedTypeConverters = mutableSetOf() - - processingEnv.elementUtils.getAllMembers(dao).forEach { element -> - if (element.kind != ElementKind.METHOD) - return@forEach - val method = element as ExecutableElement - val annotation = method.getAnnotation(UpdateSelective::class.java) ?: return@forEach - usedTypeConverters.addAll(processMethod(selective, method, annotation, typeConverters)) - } - - usedTypeConverters.forEach { converter -> - selective.addProperty(PropertySpec.builder("__${converter.converterType.simpleName}", converter.converterType.asType().asTypeName(), KModifier.PRIVATE) - .delegate(CodeBlock.builder() - .beginControlFlow("lazy") - .addStatement("%T()", converter.converterType.asType().asTypeName()) - .endControlFlow() - .build()) - .build()) - } - - FileSpec.builder(packageName, "${daoName}Selective") - .addType(selective.build()) - .build() - .writeTo(file) - } - - private fun VariableElement.name() = getAnnotation(ColumnInfo::class.java)?.name ?: simpleName.toString() - - private fun processMethod(cls: TypeSpec.Builder, method: ExecutableElement, annotation: UpdateSelective, typeConverters: List): List { - val methodName = method.simpleName.toString() - val parameter = method.parameters.first() - val paramName = parameter.simpleName.toString() - val paramTypeElement = processingEnv.typeUtils.asElement(parameter.asType()) as TypeElement - val paramTypeAnnotation = paramTypeElement.getAnnotation(Entity::class.java) - - val tableName = paramTypeAnnotation.tableName - val primaryKeys = annotation.primaryKeys - val skippedColumns = annotation.skippedColumns - - - var members = processingEnv.elementUtils.getAllMembers(paramTypeElement) - val allFields = ElementFilter.fieldsIn(members) - - // check all super classes - var superType = paramTypeElement.superclass - while (superType !is NoType) { - val superTypeElement = processingEnv.typeUtils.asElement(superType) as TypeElement - members = processingEnv.elementUtils.getAllMembers(superTypeElement) - allFields += ElementFilter.fieldsIn(members) - superType = superTypeElement.superclass - } - - allFields.removeAll { skippedColumns.contains(it.name()) } - allFields.removeAll { it.getAnnotation(Ignore::class.java) != null } - allFields.removeAll { field -> field.modifiers.any { it == Modifier.STATIC } } - val allFieldsDistinct = allFields.distinct() - - // dump fields - //processingEnv.messager.printMessage(Diagnostic.Kind.ERROR, allFieldsDistinct.joinToString()) - - val fields = allFieldsDistinct.filterNot { primaryKeys.contains(it.name()) } - val primaryFields = allFieldsDistinct.filter { primaryKeys.contains(it.name()) } - val fieldNames = fields.map { it.name() } - val primaryFieldNames = primaryFields.map { it.name() } - - val fieldNamesQuery = fieldNames.joinToString { "$it = ?" } - val primaryFieldNamesQuery = primaryFieldNames.joinToString(" AND ") { "$it = ?" } - val query = "\"\"\"UPDATE $tableName SET $fieldNamesQuery WHERE $primaryFieldNamesQuery\"\"\"" - - val entityInsertionAdapter = ClassName("androidx.room", "EntityInsertionAdapter") - val supportSQLiteStatement = ClassName("androidx.sqlite.db", "SupportSQLiteStatement") - - val usedTypeConverters = mutableListOf() - - val bind = CodeBlock.builder() - (fields+primaryFields).forEachIndexed { i, field -> - val index = i+1 - val fieldName = field.simpleName.toString() - val name = "${paramName}_$fieldName" - val realName = "${paramName}.$fieldName" - val nullable = field.getAnnotation(org.jetbrains.annotations.Nullable::class.java) != null - - var param = when (field.asType().kind) { - TypeKind.BOOLEAN -> "if ($name) 1L else 0L" - TypeKind.BYTE, - TypeKind.SHORT, - TypeKind.INT -> "$name.toLong()" - TypeKind.CHAR -> "$name.toString()" - TypeKind.FLOAT -> "$name.toDouble()" - else -> when (field.asType().toString()) { - "java.lang.String" -> name - "java.lang.Boolean" -> "if ($name == true) 1L else 0L" - "java.lang.Byte", - "java.lang.Short", - "java.lang.Integer" -> "$name.toLong()" - "java.lang.Long" -> name - "java.lang.Char" -> "$name.toString()" - "java.lang.Float" -> "$name.toDouble()" - "java.lang.Double" -> name - else -> name - } - } - - var isConvert = false - val bindMethod = when (field.asType().kind) { - TypeKind.BOOLEAN -> "bindLong" - TypeKind.BYTE -> "bindLong" - TypeKind.SHORT -> "bindLong" - TypeKind.INT -> "bindLong" - TypeKind.LONG -> "bindLong" - TypeKind.CHAR -> "bindString" - TypeKind.FLOAT -> "bindDouble" - TypeKind.DOUBLE -> "bindDouble" - else -> when (field.asType().toString()) { - "java.lang.String" -> "bindString" - "java.lang.Boolean" -> "bindLong" - "java.lang.Byte" -> "bindLong" - "java.lang.Short" -> "bindLong" - "java.lang.Integer" -> "bindLong" - "java.lang.Long" -> "bindLong" - "java.lang.Char" -> "bindString" - "java.lang.Float" -> "bindDouble" - "java.lang.Double" -> "bindDouble" - else -> { - val converter = typeConverters.firstOrNull { - it.dataType.toString() == field.asType().toString() - } - if (converter != null) { - param = "__${converter.converterType.simpleName}.${converter.methodName}($realName)" - param = when (converter.returnType.toString()) { - "java.lang.Integer", "int", - "java.lang.Short", "short", - "java.lang.Byte", "byte" -> "$param.toLong()" - "java.lang.Boolean", "boolean" -> "if ($param) 1L else 0L" - "java.lang.Char", "char" -> "$param.toString()" - "java.lang.Float", "float" -> "$param.toDouble()" - else -> param - } - isConvert = true - usedTypeConverters += converter - when (converter.returnType.toString()) { - "java.lang.Integer", "int", - "java.lang.Short", "short", - "java.lang.Byte", "byte", - "java.lang.Boolean", "boolean" -> "bindLong" - "java.lang.Char", "char" -> "bindString" - "java.lang.Float", "float" -> "bindDouble" - else -> "bindString" - } - } - else "bind${field.asType()}" - } - } - } - - if (!isConvert) { - bind.addStatement("val $name = $realName") - } - else { - bind.addStatement("val $name = $param") - param = name - } - if (nullable) { - bind.beginControlFlow("if ($name == null)") - .addStatement("stmt.bindNull($index)") - .endControlFlow() - .beginControlFlow("else") - .addStatement("stmt.$bindMethod($index, $param)") - .endControlFlow() - } - else { - bind.addStatement("stmt.$bindMethod($index, $param)") - } - } - - val adapterName = "__insertionAdapterOf$methodName" - val delegate = CodeBlock.builder().add(""" - |lazy { - | object : EntityInsertionAdapter<%T>(__db) { - | override fun createQuery() = $query - | override fun bind(stmt: %T, $paramName: %T) { - |${bind.indent().indent().indent().build()} - | } - | } - |}""".trimMargin(), paramTypeElement.asClassName(), supportSQLiteStatement, paramTypeElement.asClassName()) - - cls.addProperty(PropertySpec.builder(adapterName, entityInsertionAdapter.parameterizedBy(paramTypeElement.asClassName()), KModifier.PRIVATE) - .delegate(delegate.build()) - .build()) - - val list = ClassName("kotlin.collections", "List") - val longArray = ClassName("kotlin", "LongArray") - - val function = FunSpec.builder(methodName) - .addModifiers(KModifier.INTERNAL) - .addParameter("item", parameter.asType().asTypeName()) - .returns(Long::class.java) - .addStatement("__db.assertNotSuspendingTransaction()") - .addStatement("__db.beginTransaction()") - .addCode(""" - |try { - | val _result = $adapterName.insertAndReturnId(item) - | __db.setTransactionSuccessful() - | return _result - |} finally { - | __db.endTransaction() - |} - """.trimMargin()) - .build() - - val functionAll = FunSpec.builder(methodName+"All") - .addModifiers(KModifier.INTERNAL) - .addParameter("items", list.parameterizedBy(parameter.asType().asTypeName())) - .returns(longArray) - .addStatement("__db.assertNotSuspendingTransaction()") - .addStatement("__db.beginTransaction()") - .addCode(""" - |try { - | val _result = $adapterName.insertAndReturnIdsArray(items) - | __db.setTransactionSuccessful() - | return _result - |} finally { - | __db.endTransaction() - |} - """.trimMargin()) - .build() - - cls.addFunction(function) - cls.addFunction(functionAll) - return usedTypeConverters - } - - override fun getSupportedAnnotationTypes(): MutableSet { - return mutableSetOf(SelectiveDao::class.java.canonicalName) - } -} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1a62f29e..9bd0ad16 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed Feb 17 14:04:38 CET 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/material-about-library/build.gradle b/material-about-library/build.gradle deleted file mode 100644 index c79c427c..00000000 --- a/material-about-library/build.gradle +++ /dev/null @@ -1,38 +0,0 @@ -apply plugin: 'com.android.library' - -group = 'com.github.daniel-stoneuk' - -def versionMajor = 2 -def versionMinor = 3 -def versionPatch = 0 -def versionBuild = 0 // bump for dogfood builds, public betas, etc. - -android { - compileSdkVersion setup.compileSdk - - defaultConfig { - minSdkVersion 14 - targetSdkVersion setup.targetSdk - versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild - versionName "${versionMajor}.${versionMinor}" + (versionPatch == 0 ? "" : ".${versionPatch}") - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - debugMinify { - debuggable = true - minifyEnabled = true - proguardFiles 'proguard-android.txt' - } - } -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "androidx.appcompat:appcompat:${versions.appcompat}" - implementation "androidx.cardview:cardview:${versions.cardview}" - implementation "com.google.android.material:material:${versions.material}" -} diff --git a/material-about-library/src/main/AndroidManifest.xml b/material-about-library/src/main/AndroidManifest.xml deleted file mode 100644 index 71d1ecd9..00000000 --- a/material-about-library/src/main/AndroidManifest.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/ConvenienceBuilder.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/ConvenienceBuilder.java deleted file mode 100644 index f0e17e95..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/ConvenienceBuilder.java +++ /dev/null @@ -1,357 +0,0 @@ -package com.danielstone.materialaboutlibrary; - -import android.content.ActivityNotFoundException; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.os.Build; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; -import android.webkit.WebView; -import android.widget.Toast; - -import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem; -import com.danielstone.materialaboutlibrary.items.MaterialAboutItemOnClickAction; -import com.danielstone.materialaboutlibrary.items.MaterialAboutTitleItem; -import com.danielstone.materialaboutlibrary.model.MaterialAboutCard; -import com.danielstone.materialaboutlibrary.util.OpenSourceLicense; - -@SuppressWarnings("JavaDoc") -public class ConvenienceBuilder { - - public static MaterialAboutTitleItem createAppTitleItem(String appName, Drawable applicationIcon) { - return new MaterialAboutTitleItem(appName, null, applicationIcon); - } - - public static MaterialAboutTitleItem createAppTitleItem(Context c) { - Context applicationContext = c.getApplicationContext(); - PackageManager packageManager = applicationContext.getPackageManager(); - ApplicationInfo applicationInfo = applicationContext.getApplicationInfo(); - CharSequence appName = packageManager.getApplicationLabel(applicationInfo); - Drawable applicationIcon = packageManager.getApplicationIcon(applicationInfo); - return createAppTitleItem(appName == null ? "" : appName.toString(), applicationIcon); - } - - /** - * Creates an item with version info read from the PackageManager for current application. - * - * @param c context - * @param icon - * @param text - * @param includeVersionCode - * @return Item to add to card. - */ - public static MaterialAboutActionItem createVersionActionItem(Context c, Drawable icon, CharSequence text, boolean includeVersionCode) { - String versionName = ""; - int versionCode = 0; - try { - PackageInfo pInfo = c.getPackageManager().getPackageInfo(c.getPackageName(), 0); - versionName = pInfo.versionName; - versionCode = pInfo.versionCode; - } catch (PackageManager.NameNotFoundException ignored) { - // This shouldn't happen. - } - return new MaterialAboutActionItem.Builder() - .text(text) - .subText(versionName + (includeVersionCode ? " (" + versionCode + ")" : "")) - .icon(icon) - .build(); - } - - public static MaterialAboutItemOnClickAction createWebViewDialogOnClickAction(final Context c, final CharSequence dialogTitle, final String htmlString, final boolean isStringUrl, final boolean supportZoom) { - return createWebViewDialogOnClickAction(c, dialogTitle, c.getString(R.string.mal_close), htmlString, isStringUrl, supportZoom); - } - - public static MaterialAboutItemOnClickAction createWebViewDialogOnClickAction(final Context c, final CharSequence dialogTitle, final CharSequence dialogNegativeButton, final String htmlString, final boolean isStringUrl, final boolean supportZoom) { - - return new MaterialAboutItemOnClickAction() { - @Override - public void onClick() { - AlertDialog.Builder alertBuilder = new AlertDialog.Builder(c); - alertBuilder.setTitle(dialogTitle); - - final WebView wv = new WebView(c); - wv.getSettings().setSupportZoom(supportZoom); - if (!supportZoom) { - wv.getSettings().setLoadWithOverviewMode(true); - wv.getSettings().setUseWideViewPort(true); - } - if (isStringUrl) { - wv.loadUrl(htmlString); - } else { - wv.loadData(htmlString, "text/html; charset=utf-8", "UTF-8"); - } - - alertBuilder.setView(wv); - alertBuilder.setNegativeButton(dialogNegativeButton, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - wv.destroy(); - dialog.dismiss(); - } - }); - - final AlertDialog dialog = alertBuilder.create(); - dialog.show(); - } - }; - } - - - public static MaterialAboutActionItem createWebViewDialogItem(Context c, Drawable icon, CharSequence text, @Nullable CharSequence subText, CharSequence dialogTitle, String htmlString, boolean isStringUrl, boolean supportZoom) { - return createWebViewDialogItem(c, icon, text, subText, dialogTitle, c.getString(R.string.mal_close), htmlString, isStringUrl, supportZoom); - } - - public static MaterialAboutActionItem createWebViewDialogItem(Context c, Drawable icon, CharSequence text, @Nullable CharSequence subText, CharSequence dialogTitle, CharSequence dialogNegativeButton, String htmlString, boolean isStringUrl, boolean supportZoom) { - return new MaterialAboutActionItem.Builder() - .text(text) - .subText(subText) - .icon(icon) - .setOnClickAction(createWebViewDialogOnClickAction(c, dialogTitle, dialogNegativeButton, htmlString, isStringUrl, supportZoom)) - .build(); - } - - - public static MaterialAboutItemOnClickAction createWebsiteOnClickAction(final Context c, final Uri websiteUrl) { - return new MaterialAboutItemOnClickAction() { - @Override - public void onClick() { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(websiteUrl); - try { - c.startActivity(i); - } catch (Exception e) { - // No activity to handle intent - Toast.makeText(c, R.string.mal_activity_exception, Toast.LENGTH_SHORT).show(); - } - } - }; - } - - /** - * Creates an ActionItem which will open a url when tapped - * - * @param c context - * @param text - * @param icon - * @param websiteUrl (subText) - * @return Item to add to card. - */ - public static MaterialAboutActionItem createWebsiteActionItem(Context c, Drawable icon, CharSequence text, boolean showAddress, final Uri websiteUrl) { - return new MaterialAboutActionItem.Builder() - .text(text) - .subText((showAddress ? websiteUrl.toString() : null)) - .icon(icon) - .setOnClickAction(createWebsiteOnClickAction(c, websiteUrl)) - .build(); - } - - /** - * Creates a MaterialAboutItemOnClickAction that will open - * the Google Play store listing for the app. - * - * @param c context - * @return onClickAction - */ - public static MaterialAboutItemOnClickAction createRateOnClickAction(final Context c) { - Uri uri = Uri.parse("market://details?id=" + c.getPackageName()); - final Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | - Intent.FLAG_ACTIVITY_NEW_DOCUMENT | - Intent.FLAG_ACTIVITY_MULTIPLE_TASK); - } else { - goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | - Intent.FLAG_ACTIVITY_MULTIPLE_TASK); - } - - return new MaterialAboutItemOnClickAction() { - @Override - public void onClick() { - try { - c.startActivity(goToMarket); - } catch (ActivityNotFoundException e) { - c.startActivity(new Intent(Intent.ACTION_VIEW, - Uri.parse("http://play.google.com/store/apps/details?id=" + c.getPackageName()))); - } - } - }; - } - - /** - * Creates an ActionItem which will open the play store when tapped - * - * @param c context - * @param text - * @param subText - * @param icon - * @return Item to add to card. - */ - public static MaterialAboutActionItem createRateActionItem(Context c, Drawable icon, CharSequence text, @Nullable CharSequence subText) { - - return new MaterialAboutActionItem.Builder() - .text(text) - .subText(subText) - .icon(icon) - .setOnClickAction(createRateOnClickAction(c)) - .build(); - } - - public static MaterialAboutItemOnClickAction createEmailOnClickAction(final Context c, String email, String emailSubject) { - return createEmailOnClickAction(c, email, emailSubject, c.getString(R.string.mal_send_email)); - } - - /** - * Creates a MaterialAboutItemOnClickAction that will open - * an email intent with specified address. - * - * @param c context - * @param email email address - * @return onClickAction - */ - public static MaterialAboutItemOnClickAction createEmailOnClickAction(final Context c, String email, String emailSubject, final CharSequence chooserTitle) { - - final Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + email)); - emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject); - - return new MaterialAboutItemOnClickAction() { - @Override - public void onClick() { - try { - c.startActivity(Intent.createChooser(emailIntent, chooserTitle)); - } catch (Exception e) { - // No activity to handle intent - Toast.makeText(c, R.string.mal_activity_exception, Toast.LENGTH_SHORT).show(); - } - } - }; - } - - /** - * Creates an ActionItem which will open the an email intent when tapped - * - * @param c context - * @param text - * @param icon - * @param email email address (also used as subText) - * @return Item to add to card. - */ - public static MaterialAboutActionItem createEmailItem(Context c, Drawable icon, CharSequence text, boolean showEmail, String email, String emailSubject, CharSequence chooserTitle) { - return new MaterialAboutActionItem.Builder() - .text(text) - .subText((showEmail ? email : null)) - .icon(icon) - .setOnClickAction(createEmailOnClickAction(c, email, emailSubject, chooserTitle)) - .build(); - } - - public static MaterialAboutActionItem createEmailItem(Context c, Drawable icon, CharSequence text, boolean showEmail, String email, String emailSubject) { - return createEmailItem(c, icon, text, showEmail, email, emailSubject, c.getString(R.string.mal_send_email)); - } - - /** - * Creates a MaterialAboutItemOnClickAction that will open - * the dialer with specified number. - * - * @param c context - * @param number phone number - * @return onClickAction - */ - public static MaterialAboutItemOnClickAction createPhoneOnClickAction(final Context c, String number) { - final Intent phoneIntent = new Intent(Intent.ACTION_DIAL); - phoneIntent.setData(Uri.parse("tel:" + number)); - - return new MaterialAboutItemOnClickAction() { - @Override - public void onClick() { - try { - c.startActivity(phoneIntent); - } catch (Exception e) { - // No activity to handle intent - Toast.makeText(c, R.string.mal_activity_exception, Toast.LENGTH_SHORT).show(); - } - } - }; - } - - /** - * Creates an ActionItem which will open the dialer when tapped - * - * @param c context - * @param text - * @param icon - * @param number phone number (also used as subText) - * @return Item to add to card. - */ - public static MaterialAboutActionItem createPhoneItem(Context c, Drawable icon, CharSequence text, boolean showNumber, String number) { - return new MaterialAboutActionItem.Builder() - .text(text) - .subText((showNumber ? number : null)) - .icon(icon) - .setOnClickAction(createPhoneOnClickAction(c, number)) - .build(); - } - - /** - * Creates a MaterialAboutItemOnClickAction that will open - * maps with a query. - * Query can be either lat,lng(label) or written address - * - * @param c context - * @param addressQuery address query - * @return onClickAction - */ - public static MaterialAboutItemOnClickAction createMapOnClickAction(final Context c, String addressQuery) { - final Intent mapIntent = new Intent(Intent.ACTION_VIEW); - mapIntent.setData(Uri.parse("geo:0,0").buildUpon().appendQueryParameter("q", addressQuery).build()); - return new MaterialAboutItemOnClickAction() { - @Override - public void onClick() { - try { - c.startActivity(mapIntent); - } catch (Exception e) { - // No activity to handle intent - Toast.makeText(c, R.string.mal_activity_exception, Toast.LENGTH_SHORT).show(); - } - } - }; - } - - /** - * Creates an ActionItem which will open maps when tapped - * Query can be either lat,lng(label) or written address - * - * @param c context - * @param text - * @param subText can be set to null - * @param icon - * @param addressQuery addressQuery - * @return Item to add to card. - */ - public static MaterialAboutActionItem createMapItem(Context c, Drawable icon, CharSequence text, CharSequence subText, String addressQuery) { - return new MaterialAboutActionItem.Builder() - .text(text) - .subText(subText) - .icon(icon) - .setOnClickAction(createMapOnClickAction(c, addressQuery)) - .build(); - } - - public static MaterialAboutCard createLicenseCard(Context c, Drawable icon, CharSequence libraryTitle, CharSequence year, CharSequence name, OpenSourceLicense license) { - - MaterialAboutActionItem licenseItem = new MaterialAboutActionItem.Builder() - .icon(icon) - .setIconGravity(MaterialAboutActionItem.GRAVITY_TOP) - .text(libraryTitle) - .subText(String.format(c.getString(license.getResourceId()), year, name)) - .build(); - - return new MaterialAboutCard.Builder().addItem(licenseItem).build(); - } - -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/MaterialAboutActivity.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/MaterialAboutActivity.java deleted file mode 100644 index 9a5ec841..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/MaterialAboutActivity.java +++ /dev/null @@ -1,186 +0,0 @@ -package com.danielstone.materialaboutlibrary; - - -import android.content.Context; -import android.os.AsyncTask; -import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import com.google.android.material.appbar.AppBarLayout; -import androidx.interpolator.view.animation.FastOutSlowInInterpolator; -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.app.AppCompatActivity; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import androidx.recyclerview.widget.SimpleItemAnimator; -import androidx.appcompat.widget.Toolbar; -import android.util.TypedValue; -import android.view.MenuItem; - -import com.danielstone.materialaboutlibrary.adapters.MaterialAboutListAdapter; -import com.danielstone.materialaboutlibrary.model.MaterialAboutList; -import com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import java.lang.ref.WeakReference; - -public abstract class MaterialAboutActivity extends AppCompatActivity { - - private MaterialAboutList list = new MaterialAboutList.Builder().build(); - private Toolbar toolbar; - private RecyclerView recyclerView; - private MaterialAboutListAdapter adapter; - - @NonNull - protected abstract MaterialAboutList getMaterialAboutList(@NonNull Context context); - - @Nullable - protected abstract CharSequence getActivityTitle(); - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - verifyAttributesExist(); - - setContentView(R.layout.mal_material_about_activity); - - CharSequence title = getActivityTitle(); - if (title == null) - setTitle(R.string.mal_title_about); - else - setTitle(title); - - - assignViews(); - initViews(); - - ListTask task = new ListTask(this); - task.execute(); - } - - private void verifyAttributesExist() { - TypedValue typedValue = new TypedValue(); - boolean malColorPrimaryExists = - getTheme().resolveAttribute(R.attr.mal_color_primary, typedValue, true); - boolean malColorSecondaryExists = - getTheme().resolveAttribute(R.attr.mal_color_secondary, typedValue, true); - if (!malColorPrimaryExists || !malColorSecondaryExists) { - throw new IllegalStateException(String.format("The current theme doesn't provide %s " + - "and/or %s. Please use a theme provided by the library or an extension.", - getResources().getResourceEntryName(R.attr.mal_color_primary), - getResources().getResourceEntryName(R.attr.mal_color_secondary))); - } - } - - private void assignViews() { - toolbar = (Toolbar) findViewById(R.id.mal_toolbar); - recyclerView = (RecyclerView) findViewById(R.id.mal_recyclerview); - recyclerView.setAlpha(0f); - recyclerView.setTranslationY(20); - } - - private void initViews() { - setSupportActionBar(toolbar); - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - actionBar.setDisplayHomeAsUpEnabled(true); - } - adapter = new MaterialAboutListAdapter(getViewTypeManager()); - recyclerView.setLayoutManager(new LinearLayoutManager(this)); - recyclerView.setAdapter(adapter); - RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator(); - if (animator instanceof SimpleItemAnimator) { - ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false); - } - } - - @NonNull - protected ViewTypeManager getViewTypeManager() { - return new DefaultViewTypeManager(); - } - - @NonNull - protected MaterialAboutList getList() { - return list; - } - - protected boolean shouldAnimate() { - return true; - } - - protected void refreshMaterialAboutList() { - setMaterialAboutList(list); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - onBackPressed(); - return true; - } - return super.onOptionsItemSelected(item); - } - - private void onTaskFinished(@Nullable MaterialAboutList materialAboutList) { - if (materialAboutList != null) { - list = materialAboutList; - adapter.setData(list.getCards()); - - if (shouldAnimate()) { - recyclerView.animate() - .alpha(1f) - .translationY(0f) - .setDuration(600) - .setInterpolator(new FastOutSlowInInterpolator()).start(); - } else { - recyclerView.setAlpha(1f); - recyclerView.setTranslationY(0f); - } - } else { - finish();//?? why we remain here anyway? - } - } - - protected void setMaterialAboutList(MaterialAboutList materialAboutList) { - list = materialAboutList; - adapter.setData(list.getCards()); - } - - protected void setScrollToolbar(boolean scrollToolbar) { - if (toolbar != null) { - AppBarLayout.LayoutParams params = - (AppBarLayout.LayoutParams) toolbar.getLayoutParams(); - if (scrollToolbar) { - params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL - | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS); - } else { - params.setScrollFlags(0); - } - } - } - - private static class ListTask extends AsyncTask { - - private WeakReference context; - - ListTask(MaterialAboutActivity context) { - this.context = new WeakReference<>(context); - } - - @Override - protected MaterialAboutList doInBackground(String... params) { - return isCancelled() || context.get() == null ? null : context.get().getMaterialAboutList(context.get()); - } - - @Override - protected void onPostExecute(MaterialAboutList materialAboutList) { - super.onPostExecute(materialAboutList); - if (context.get() != null) { - if (!context.get().isFinishing()) { - context.get().onTaskFinished(materialAboutList); - } - } - context = null; - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/MaterialAboutFragment.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/MaterialAboutFragment.java deleted file mode 100644 index c3ad1f04..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/MaterialAboutFragment.java +++ /dev/null @@ -1,132 +0,0 @@ -package com.danielstone.materialaboutlibrary; - -import android.content.Context; -import android.os.AsyncTask; -import android.os.Bundle; - -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.interpolator.view.animation.FastOutSlowInInterpolator; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import androidx.recyclerview.widget.SimpleItemAnimator; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import com.danielstone.materialaboutlibrary.adapters.MaterialAboutListAdapter; -import com.danielstone.materialaboutlibrary.model.MaterialAboutList; -import com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -public abstract class MaterialAboutFragment extends Fragment { - - private MaterialAboutList list = new MaterialAboutList.Builder().build(); - private RecyclerView recyclerView; - private MaterialAboutListAdapter adapter; - - public static MaterialAboutFragment newInstance(MaterialAboutFragment fragment) { - return fragment; - } - - protected abstract MaterialAboutList getMaterialAboutList(Context activityContext); - - protected int getTheme() { - return R.style.Theme_Mal_Light; - } - - protected boolean shouldAnimate() { - return true; - } - - - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - int style = getTheme(); - - // create ContextThemeWrapper from the original Activity Context with the custom theme - final Context contextThemeWrapper = new android.view.ContextThemeWrapper(getActivity(), style); - LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper); - View rootView = localInflater.inflate(R.layout.mal_material_about_fragment, container, false); - - recyclerView = (RecyclerView) rootView.findViewById(R.id.mal_recyclerview); - adapter = new MaterialAboutListAdapter(getViewTypeManager()); - recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); - recyclerView.setAdapter(adapter); - - RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator(); - if (animator instanceof SimpleItemAnimator) { - ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false); - } - - recyclerView.setAlpha(0f); - recyclerView.setTranslationY(20); - - ListTask task = new ListTask(getActivity()); - task.execute(); - - return rootView; - } - - protected ViewTypeManager getViewTypeManager() { - return new DefaultViewTypeManager(); - } - - protected MaterialAboutList getList() { - return list; - } - - protected void setMaterialAboutList(MaterialAboutList materialAboutList) { - //recyclerView.stopScroll(); - //recyclerView.getRecycledViewPool().clear(); - list = materialAboutList; - adapter.setData(list.getCards()); - } - - @Override - public void onPause() { - super.onPause(); - } - - protected void refreshMaterialAboutList() { - setMaterialAboutList(list); - } - - private class ListTask extends AsyncTask { - - Context fragmentContext; - - public ListTask(Context activityContext) { - this.fragmentContext = activityContext; - } - - @Override - protected String doInBackground(String... params) { - list = getMaterialAboutList(fragmentContext); - return null; - } - - @Override - protected void onPostExecute(String s) { - if (list == null) - return;// TODO: 2019-05-09 dirty fix tbh - adapter.setData(list.getCards()); - - if (shouldAnimate()) { - recyclerView.animate() - .alpha(1f) - .translationY(0f) - .setDuration(600) - .setInterpolator(new FastOutSlowInInterpolator()) - .start(); - } else { - recyclerView.setAlpha(1f); - recyclerView.setTranslationY(0f); - } - - super.onPostExecute(s); - fragmentContext = null; - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/adapters/MaterialAboutItemAdapter.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/adapters/MaterialAboutItemAdapter.java deleted file mode 100644 index a3cd1e47..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/adapters/MaterialAboutItemAdapter.java +++ /dev/null @@ -1,167 +0,0 @@ -package com.danielstone.materialaboutlibrary.adapters; - -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.AsyncListDiffer; -import androidx.recyclerview.widget.DiffUtil; -import androidx.recyclerview.widget.RecyclerView; - -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.items.MaterialAboutItem; -import com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class MaterialAboutItemAdapter extends RecyclerView.Adapter { - - private final AsyncListDiffer differ = new AsyncListDiffer(this, DIFF_CALLBACK); - - private ViewTypeManager viewTypeManager; - - private Context context; - - private List data = new ArrayList<>(); - private List oldData = new ArrayList<>(); - - MaterialAboutItemAdapter() { - setHasStableIds(true); - this.viewTypeManager = new DefaultViewTypeManager(); - } - - MaterialAboutItemAdapter(ViewTypeManager customViewTypeManager) { - //Log.d("MaterialItem", "Created adapter"); - setHasStableIds(true); - this.viewTypeManager = customViewTypeManager; - } - - @NonNull - @Override - public MaterialAboutItemViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) { - context = viewGroup.getContext(); - if (!(viewGroup instanceof RecyclerView)) { - throw new RuntimeException("Not bound to RecyclerView"); - } - - int layoutId = viewTypeManager.getLayout(viewType); - - View view = LayoutInflater.from(viewGroup.getContext()).inflate(layoutId, viewGroup, false); - view.setFocusable(true); - - return viewTypeManager.getViewHolder(viewType, view); - } - - @Override - public void onBindViewHolder(MaterialAboutItemViewHolder holder, int position) { - /*if (data.get(position) instanceof MaterialAboutSwitchItem) { - Log.d("MaterialAdapter", "Item "+((MaterialAboutSwitchItem) data.get(position)).getText()+" checked "+((MaterialAboutSwitchItem) data.get(position)).getChecked()); - }*/ - //Log.d("MaterialItem", "Binding "+data.get(position).getDetailString()); - viewTypeManager.setupItem(getItemViewType(position), holder, data.get(position), context); - } - - - @Override - public long getItemId(int position) { - return UUID.fromString(data.get(position).getId()).getMostSignificantBits() & Long.MAX_VALUE; - } - - @Override - public int getItemCount() { - return data.size(); - } - - @Override - public int getItemViewType(int position) { - return data.get(position).getType(); - } - - public void setData(ArrayList data) { - this.data = data; - - notifyDataSetChanged(); - // diff this with previous data - /*DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new MyDiffCallback(oldData, data)); - try { - diffResult.dispatchUpdatesTo(this); - } - catch (IllegalStateException e) { - e.printStackTrace(); - } - - // clone the new data to make further diffs - oldData = new ArrayList<>(); - for (MaterialAboutItem item : data) { - oldData.add(item.clone()); - }*/ - - /*List newData = new ArrayList<>(); - for (MaterialAboutItem item : data) { - newData.add(item.clone()); - } - differ.submitList(newData);*/ - } - - public List getData() { - return data; - } - - - public static final DiffUtil.ItemCallback DIFF_CALLBACK = new DiffUtil.ItemCallback() { - @Override - public boolean areItemsTheSame(MaterialAboutItem oldItem, MaterialAboutItem newItem) { - return oldItem.getId().equals(newItem.getId()); - } - - @Override - public boolean areContentsTheSame(MaterialAboutItem oldItem, MaterialAboutItem newItem) { - return oldItem.getDetailString().equals(newItem.getDetailString()); - } - }; - - public class MyDiffCallback extends DiffUtil.Callback{ - - List oldPersons; - List newPersons; - - public MyDiffCallback(List newPersons, List oldPersons) { - this.newPersons = newPersons; - this.oldPersons = oldPersons; - } - - @Override - public int getOldListSize() { - return oldPersons.size(); - } - - @Override - public int getNewListSize() { - return newPersons.size(); - } - - @Override - public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) { - return oldPersons.get(oldItemPosition).getId().equals(newPersons.get(newItemPosition).getId()); - } - - @Override - public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) { - return oldPersons.get(oldItemPosition).getDetailString().equals(newPersons.get(newItemPosition).getDetailString()); - } - - @Nullable - @Override - public Object getChangePayload(int oldItemPosition, int newItemPosition) { - //you can return particular field for changed item. - return super.getChangePayload(oldItemPosition, newItemPosition); - } - } - -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/adapters/MaterialAboutListAdapter.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/adapters/MaterialAboutListAdapter.java deleted file mode 100644 index e795ee31..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/adapters/MaterialAboutListAdapter.java +++ /dev/null @@ -1,237 +0,0 @@ -package com.danielstone.materialaboutlibrary.adapters; - -import android.content.Context; - -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.AsyncListDiffer; -import androidx.recyclerview.widget.DiffUtil; -import androidx.cardview.widget.CardView; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.model.MaterialAboutCard; -import com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; -import com.google.android.material.card.MaterialCardView; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class MaterialAboutListAdapter extends RecyclerView.Adapter { - - private final AsyncListDiffer differ = new AsyncListDiffer(this, DIFF_CALLBACK); - - private ViewTypeManager viewTypeManager; - - private Context context; - - private List data = new ArrayList<>(); - private List oldData = new ArrayList<>(); - - public MaterialAboutListAdapter() { - setHasStableIds(true); - this.viewTypeManager = new DefaultViewTypeManager(); - } - - public MaterialAboutListAdapter(ViewTypeManager customViewTypeManager) { - //Log.d("MaterialList", "Created list adapter"); - setHasStableIds(true); - this.viewTypeManager = customViewTypeManager; - } - - @Override - public MaterialAboutListViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { - context = viewGroup.getContext(); - if (viewGroup instanceof RecyclerView) { - View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.mal_material_about_list_card, viewGroup, false); - view.setFocusable(true); - return new MaterialAboutListViewHolder(view); - } else { - throw new RuntimeException("Not bound to RecyclerView"); - } - } - - @Override - public void onBindViewHolder(MaterialAboutListViewHolder holder, int position) { - MaterialAboutCard card = data.get(position); - - if (holder.cardView instanceof CardView) { - CardView cardView = (CardView) holder.cardView; - int cardColor = card.getCardColor(); - if (cardColor != 0) { - cardView.setCardBackgroundColor(cardColor); - } - } - - CharSequence title = card.getTitle(); - int titleRes = card.getTitleRes(); - - holder.title.setVisibility(View.VISIBLE); - if (title != null) { - holder.title.setText(title); - } else if (titleRes != 0) { - holder.title.setText(titleRes); - } else { - holder.title.setVisibility(View.GONE); - } - - int titleColor = card.getTitleColor(); - - if (holder.title.getVisibility() == View.VISIBLE) { - if (titleColor != 0) { - holder.title.setTextColor(titleColor); - } else { - holder.title.setTextColor(holder.title.getTextColors().getDefaultColor()); - } - } - - if (card.getCustomAdapter() != null) { - holder.useCustomAdapter(card.getCustomAdapter()); - } else { - holder.useMaterialAboutItemAdapter(); - ((MaterialAboutItemAdapter) holder.adapter).setData(card.getItems()); - } - } - - @Override - public long getItemId(int position) { - return UUID.fromString(data.get(position).getId()).getMostSignificantBits() & Long.MAX_VALUE; - } - - @Override - public int getItemCount() { - return data.size(); - } - - public void setData(ArrayList data) { - this.data = data; - - notifyDataSetChanged(); - - /*// diff this with previous data - DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new MyDiffCallback(oldData, data)); - try { - diffResult.dispatchUpdatesTo(this); - } - catch (IllegalStateException e) { - e.printStackTrace(); - } - - // clone the new data to make further diffs - oldData = new ArrayList<>(); - for (MaterialAboutCard card : data) { - oldData.add(card.clone()); - }*/ - //differ.submitList(newData); - } - - - List getData() { - return data; - } - - class MaterialAboutListViewHolder extends RecyclerView.ViewHolder { - - final View cardView; - final TextView title; - final RecyclerView recyclerView; - RecyclerView.Adapter adapter; - - MaterialAboutListViewHolder(View view) { - super(view); - cardView = view.findViewById(R.id.mal_list_card); - title = (TextView) view.findViewById(R.id.mal_list_card_title); - recyclerView = (RecyclerView) view.findViewById(R.id.mal_card_recyclerview); - adapter = new MaterialAboutItemAdapter(viewTypeManager); - recyclerView.setLayoutManager(new LinearLayoutManager(context)); - recyclerView.setAdapter(adapter); - recyclerView.setNestedScrollingEnabled(false); - } - - public void useMaterialAboutItemAdapter() { - if (!(adapter instanceof MaterialAboutItemAdapter)) { - adapter = new MaterialAboutItemAdapter(viewTypeManager); - recyclerView.setLayoutManager(new LinearLayoutManager(context)); - recyclerView.setAdapter(adapter); - } - } - - public void useCustomAdapter(RecyclerView.Adapter newAdapter) { - if (adapter instanceof MaterialAboutItemAdapter) { - recyclerView.setLayoutManager(new LinearLayoutManager(context)); - recyclerView.setAdapter(newAdapter); - } - } - } - - - public static final DiffUtil.ItemCallback DIFF_CALLBACK = new DiffUtil.ItemCallback() { - @Override - public boolean areItemsTheSame(MaterialAboutCard oldItem, MaterialAboutCard newItem) { - return oldItem.getId().equals(newItem.getId()); - } - - @Override - public boolean areContentsTheSame(MaterialAboutCard oldCard, MaterialAboutCard newCard) { - boolean result; - result = oldCard.toString().equals(newCard.toString()); - if (oldCard.getItems().size() != newCard.getItems().size()) return false; - for (int i = 0; i < oldCard.getItems().size(); i++) { - if (!oldCard.getItems().get(i).getDetailString().equals(newCard.getItems().get(i).getDetailString())) return false; - } - return result; - } - }; - - public class MyDiffCallback extends DiffUtil.Callback{ - - List oldPersons; - List newPersons; - - public MyDiffCallback(List newPersons, List oldPersons) { - this.newPersons = newPersons; - this.oldPersons = oldPersons; - } - - @Override - public int getOldListSize() { - return oldPersons.size(); - } - - @Override - public int getNewListSize() { - return newPersons.size(); - } - - @Override - public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) { - return oldPersons.get(oldItemPosition).getId().equals(newPersons.get(newItemPosition).getId()); - } - - @Override - public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) { - boolean result; - result = oldPersons.get(oldItemPosition).toString().equals(newPersons.get(newItemPosition).toString()); - if (oldPersons.get(oldItemPosition).getItems().size() != newPersons.get(newItemPosition).getItems().size()) return false; - for (int i = 0; i < oldPersons.get(oldItemPosition).getItems().size(); i++) { - if (!oldPersons.get(oldItemPosition).getItems().get(i).getDetailString().equals(newPersons.get(newItemPosition).getItems().get(i).getDetailString())) return false; - } - return result; - } - - @Nullable - @Override - public Object getChangePayload(int oldItemPosition, int newItemPosition) { - //you can return particular field for changed item. - return super.getChangePayload(oldItemPosition, newItemPosition); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/holders/MaterialAboutItemViewHolder.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/holders/MaterialAboutItemViewHolder.java deleted file mode 100644 index 6188817b..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/holders/MaterialAboutItemViewHolder.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.danielstone.materialaboutlibrary.holders; - -import androidx.recyclerview.widget.RecyclerView; -import android.view.View; - -public abstract class MaterialAboutItemViewHolder extends RecyclerView.ViewHolder { - - public MaterialAboutItemViewHolder(View itemView) { - super(itemView); - } - -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutActionItem.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutActionItem.java deleted file mode 100644 index c69f106d..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutActionItem.java +++ /dev/null @@ -1,488 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.os.Build; - -import androidx.annotation.ColorInt; -import androidx.annotation.DrawableRes; -import androidx.annotation.IntDef; -import androidx.annotation.StringRes; -import android.text.Html; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.View; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import static android.view.View.GONE; - -public class MaterialAboutActionItem extends MaterialAboutItem { - - public static final int GRAVITY_TOP = 0; - public static final int GRAVITY_MIDDLE = 1; - public static final int GRAVITY_BOTTOM = 2; - private CharSequence text = null; - private int textRes = 0; - private CharSequence subText = null; - private int subTextRes = 0; - private int textColor = -1; - private int subTextColor = -1; - private Drawable icon = null; - private int iconRes = 0; - private boolean showIcon = true; - private int iconGravity = GRAVITY_MIDDLE; - private MaterialAboutItemOnClickAction onClickAction = null; - private MaterialAboutItemOnClickAction onLongClickAction = null; - - private MaterialAboutActionItem(Builder builder) { - super(); - this.text = builder.text; - this.textRes = builder.textRes; - - this.subText = builder.subText; - this.subTextRes = builder.subTextRes; - - this.textColor = builder.textColor; - this.subTextColor = builder.subTextColor; - - this.icon = builder.icon; - this.iconRes = builder.iconRes; - - this.showIcon = builder.showIcon; - - this.iconGravity = builder.iconGravity; - - this.onClickAction = builder.onClickAction; - this.onLongClickAction = builder.onLongClickAction; - } - - public MaterialAboutActionItem(CharSequence text, CharSequence subText, Drawable icon, MaterialAboutItemOnClickAction onClickAction) { - this.text = text; - this.subText = subText; - this.icon = icon; - this.onClickAction = onClickAction; - } - - public MaterialAboutActionItem(CharSequence text, CharSequence subText, Drawable icon) { - this.text = text; - this.subText = subText; - this.icon = icon; - } - - public MaterialAboutActionItem(int textRes, int subTextRes, int iconRes, MaterialAboutItemOnClickAction onClickAction) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - this.onClickAction = onClickAction; - } - - public MaterialAboutActionItem(int textRes, int subTextRes, int iconRes) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - } - - public static MaterialAboutItemViewHolder getViewHolder(View view) { - return new MaterialAboutActionItemViewHolder(view); - } - - public static void setupItem(MaterialAboutActionItemViewHolder holder, MaterialAboutActionItem item, Context context) { - CharSequence text = item.getText(); - int textRes = item.getTextRes(); - - holder.text.setVisibility(View.VISIBLE); - if (text != null) { - holder.text.setText(text); - } else if (textRes != 0) { - holder.text.setText(textRes); - } else { - holder.text.setVisibility(GONE); - } - - CharSequence subText = item.getSubText(); - int subTextRes = item.getSubTextRes(); - - holder.subText.setVisibility(View.VISIBLE); - if (subText != null) { - holder.subText.setText(subText); - } else if (subTextRes != 0) { - holder.subText.setText(subTextRes); - } else { - holder.subText.setVisibility(GONE); - } - - if (item.getTextColor() != -1) { - holder.text.setTextColor(item.getTextColor()); - } - if (item.getSubTextColor() != -1) { - holder.subText.setTextColor(item.getSubTextColor()); - } - - if (item.shouldShowIcon()) { - holder.icon.setVisibility(View.VISIBLE); - Drawable drawable = item.getIcon(); - int drawableRes = item.getIconRes(); - if (drawable != null) { - holder.icon.setImageDrawable(drawable); - } else if (drawableRes != 0) { - holder.icon.setImageResource(drawableRes); - } - } else { - holder.icon.setVisibility(GONE); - } - - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) holder.icon.getLayoutParams(); - switch (item.getIconGravity()) { - case MaterialAboutActionItem.GRAVITY_TOP: - params.gravity = Gravity.TOP; - break; - case MaterialAboutActionItem.GRAVITY_MIDDLE: - params.gravity = Gravity.CENTER_VERTICAL; - break; - case MaterialAboutActionItem.GRAVITY_BOTTOM: - params.gravity = Gravity.BOTTOM; - break; - } - holder.icon.setLayoutParams(params); - - int pL = 0, pT = 0, pR = 0, pB = 0; - if (Build.VERSION.SDK_INT < 21) { - pL = holder.view.getPaddingLeft(); - pT = holder.view.getPaddingTop(); - pR = holder.view.getPaddingRight(); - pB = holder.view.getPaddingBottom(); - } - - if (item.getOnClickAction() != null || item.getOnLongClickAction() != null) { - TypedValue outValue = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true); - holder.view.setBackgroundResource(outValue.resourceId); - } else { - holder.view.setBackgroundResource(0); - } - holder.setOnClickAction(item.getOnClickAction()); - holder.setOnLongClickAction(item.getOnLongClickAction()); - - if (Build.VERSION.SDK_INT < 21) { - holder.view.setPadding(pL, pT, pR, pB); - } - } - - @Override - public int getType() { - return ViewTypeManager.ItemType.ACTION_ITEM; - } - - @Override - public String getDetailString() { - return "MaterialAboutActionItem{" + - "text=" + text + - ", textRes=" + textRes + - ", subText=" + subText + - ", subTextRes=" + subTextRes + - ", textColor=" + textColor + - ", descColor=" + subTextColor + - ", icon=" + icon + - ", iconRes=" + iconRes + - ", showIcon=" + showIcon + - ", iconGravity=" + iconGravity + - ", onClickAction=" + onClickAction + - ", onLongClickAction=" + onLongClickAction + - '}'; - } - - public MaterialAboutActionItem(MaterialAboutActionItem item) { - this.id = item.getId(); - this.text = item.getText(); - this.textRes = item.getTextRes(); - this.subText = item.getSubText(); - this.subTextRes = item.getSubTextRes(); - this.textColor = item.getTextColor(); - this.subTextColor = item.getSubTextColor(); - this.icon = item.getIcon(); - this.iconRes = item.getIconRes(); - this.showIcon = item.showIcon; - this.iconGravity = item.iconGravity; - this.onClickAction = item.onClickAction; - this.onLongClickAction = item.onLongClickAction; - } - - @Override - public MaterialAboutItem clone() { - return new MaterialAboutActionItem(this); - } - - public CharSequence getText() { - return text; - } - public MaterialAboutActionItem setText(CharSequence text) { - this.textRes = 0; - this.text = text; - return this; - } - - public int getTextRes() { - return textRes; - } - - public MaterialAboutActionItem setTextRes(int textRes) { - this.text = null; - this.textRes = textRes; - return this; - } - - public CharSequence getSubText() { - return subText; - } - - public MaterialAboutActionItem setSubText(CharSequence subText) { - this.subTextRes = 0; - this.subText = subText; - return this; - } - - public int getSubTextRes() { - return subTextRes; - } - - public MaterialAboutActionItem setSubTextRes(int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public int getTextColor() { - return textColor; - } - - public MaterialAboutActionItem setTextColor(int textColor) { - this.textColor = textColor; - return this; - } - - public int getSubTextColor() { - return subTextColor; - } - - public MaterialAboutActionItem setSubTextColor(int subTextColor) { - this.subTextColor = subTextColor; - return this; - } - - public Drawable getIcon() { - return icon; - } - - public MaterialAboutActionItem setIcon(Drawable icon) { - this.iconRes = 0; - this.icon = icon; - return this; - } - - public int getIconRes() { - return iconRes; - } - - public MaterialAboutActionItem setIconRes(int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public boolean shouldShowIcon() { - return showIcon; - } - - public MaterialAboutActionItem setShouldShowIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - @IconGravity - public int getIconGravity() { - return iconGravity; - } - - public MaterialAboutActionItem setIconGravity(int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public MaterialAboutItemOnClickAction getOnClickAction() { - return onClickAction; - } - - public MaterialAboutActionItem setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public MaterialAboutItemOnClickAction getOnLongClickAction() { - return onLongClickAction; - } - - public MaterialAboutActionItem setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - - @Retention(RetentionPolicy.SOURCE) - @IntDef({GRAVITY_TOP, GRAVITY_MIDDLE, GRAVITY_BOTTOM}) - public @interface IconGravity { - } - - public static class MaterialAboutActionItemViewHolder extends MaterialAboutItemViewHolder implements View.OnClickListener, View.OnLongClickListener { - public final View view; - public final ImageView icon; - public final TextView text; - public final TextView subText; - private MaterialAboutItemOnClickAction onClickAction; - private MaterialAboutItemOnClickAction onLongClickAction; - - MaterialAboutActionItemViewHolder(View view) { - super(view); - this.view = view; - icon = (ImageView) view.findViewById(R.id.mal_item_image); - text = (TextView) view.findViewById(R.id.mal_item_text); - subText = (TextView) view.findViewById(R.id.mal_action_item_subtext); - } - - public void setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - view.setOnClickListener(onClickAction != null ? this : null); - } - - public void setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - view.setOnLongClickListener(onLongClickAction != null ? this : null); - } - - @Override - public void onClick(View v) { - if (onClickAction != null) { - onClickAction.onClick(); - } - } - - @Override - public boolean onLongClick(View v) { - if (onLongClickAction != null) { - onLongClickAction.onClick(); - return true; - } - return false; - } - } - - public static class Builder { - - MaterialAboutItemOnClickAction onClickAction = null; - MaterialAboutItemOnClickAction onLongClickAction = null; - private CharSequence text = null; - @StringRes - private int textRes = 0; - private CharSequence subText = null; - @StringRes - private int subTextRes = 0; - @ColorInt - private int textColor = -1; - @ColorInt - private int subTextColor = -1; - private Drawable icon = null; - @DrawableRes - private int iconRes = 0; - private boolean showIcon = true; - @IconGravity - private int iconGravity = GRAVITY_MIDDLE; - - public Builder text(CharSequence text) { - this.text = text; - this.textRes = 0; - return this; - } - - public Builder text(@StringRes int text) { - this.textRes = text; - this.text = null; - return this; - } - - public Builder subText(CharSequence subText) { - this.subText = subText; - this.subTextRes = 0; - return this; - } - - public Builder subText(@StringRes int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public Builder textColor(@ColorInt int textColor) { - this.textColor = textColor; - return this; - } - - public Builder subTextColor(@ColorInt int subTextColor) { - this.subTextColor = subTextColor; - return this; - } - - public Builder subTextHtml(String subTextHtml) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - this.subText = Html.fromHtml(subTextHtml, Html.FROM_HTML_MODE_LEGACY); - } else { - //noinspection deprecation - this.subText = Html.fromHtml(subTextHtml); - } - this.subTextRes = 0; - return this; - } - - public Builder icon(Drawable icon) { - this.icon = icon; - this.iconRes = 0; - return this; - } - - public Builder icon(@DrawableRes int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public Builder showIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - public Builder setIconGravity(@IconGravity int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public Builder setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public Builder setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - - public MaterialAboutActionItem build() { - return new MaterialAboutActionItem(this); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutActionSwitchItem.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutActionSwitchItem.java deleted file mode 100644 index eb6d9411..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutActionSwitchItem.java +++ /dev/null @@ -1,606 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.os.Build; -import androidx.annotation.DrawableRes; -import androidx.annotation.IntDef; -import androidx.annotation.StringRes; -import androidx.appcompat.widget.SwitchCompat; - -import android.text.Html; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.Switch; -import android.widget.TextView; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import static android.view.View.GONE; - -public class MaterialAboutActionSwitchItem extends MaterialAboutItem { - - public static final int GRAVITY_TOP = 0; - public static final int GRAVITY_MIDDLE = 1; - public static final int GRAVITY_BOTTOM = 2; - private CharSequence text = null; - private int textRes = 0; - private CharSequence subText = null; - private int subTextRes = 0; - private CharSequence subTextChecked = null; - private int subTextCheckedRes = 0; - private Drawable icon = null; - private int iconRes = 0; - private boolean showIcon = true; - private int iconGravity = GRAVITY_MIDDLE; - private boolean checked = false; - private int tag = -1; - private MaterialAboutItemOnClickAction onClickAction = null; - private MaterialAboutItemOnClickAction onLongClickAction = null; - private MaterialAboutItemOnChangeAction onChangeAction = null; - - private MaterialAboutActionSwitchItem(Builder builder) { - super(); - this.text = builder.text; - this.textRes = builder.textRes; - - this.subText = builder.subText; - this.subTextRes = builder.subTextRes; - - this.subTextChecked = builder.subTextChecked; - this.subTextCheckedRes = builder.subTextCheckedRes; - - this.icon = builder.icon; - this.iconRes = builder.iconRes; - - this.showIcon = builder.showIcon; - - this.iconGravity = builder.iconGravity; - - this.checked = builder.checked; - - this.tag = builder.tag; - - this.onClickAction = builder.onClickAction; - this.onLongClickAction = builder.onLongClickAction; - this.onChangeAction = builder.onChangeAction; - } - - public MaterialAboutActionSwitchItem(CharSequence text, CharSequence subText, Drawable icon, MaterialAboutItemOnChangeAction onChangeAction) { - this.text = text; - this.subText = subText; - this.icon = icon; - this.onChangeAction = onChangeAction; - } - - public MaterialAboutActionSwitchItem(CharSequence text, CharSequence subText, Drawable icon) { - this.text = text; - this.subText = subText; - this.icon = icon; - } - - public MaterialAboutActionSwitchItem(int textRes, int subTextRes, int iconRes, MaterialAboutItemOnChangeAction onChangeAction) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - this.onChangeAction = onChangeAction; - } - - public MaterialAboutActionSwitchItem(int textRes, int subTextRes, int iconRes) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - } - - public static void setupItem(MaterialAboutActionSwitchItemViewHolder holder, MaterialAboutActionSwitchItem item, Context context) { - holder.switchItem = item; - - CharSequence text = item.getText(); - int textRes = item.getTextRes(); - - holder.text.setVisibility(View.VISIBLE); - if (text != null) { - holder.text.setText(text); - } else if (textRes != 0) { - holder.text.setText(textRes); - } else { - holder.text.setVisibility(GONE); - } - - CharSequence subText = item.getSubText(); - int subTextRes = item.getSubTextRes(); - - holder.subText.setVisibility(View.VISIBLE); - if (subText != null) { - holder.subText.setText(subText); - } else if (subTextRes != 0) { - holder.subText.setText(subTextRes); - } else { - holder.subText.setVisibility(GONE); - } - - if (item.shouldShowIcon()) { - holder.icon.setVisibility(View.VISIBLE); - Drawable drawable = item.getIcon(); - int drawableRes = item.getIconRes(); - if (drawable != null) { - holder.icon.setImageDrawable(drawable); - } else if (drawableRes != 0) { - holder.icon.setImageResource(drawableRes); - } - } else { - holder.icon.setVisibility(GONE); - } - - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) holder.icon.getLayoutParams(); - switch (item.getIconGravity()) { - case MaterialAboutActionSwitchItem.GRAVITY_TOP: - params.gravity = Gravity.TOP; - break; - case MaterialAboutActionSwitchItem.GRAVITY_MIDDLE: - params.gravity = Gravity.CENTER_VERTICAL; - break; - case MaterialAboutActionSwitchItem.GRAVITY_BOTTOM: - params.gravity = Gravity.BOTTOM; - break; - } - holder.icon.setLayoutParams(params); - - int pL = 0, pT = 0, pR = 0, pB = 0; - if (Build.VERSION.SDK_INT < 21) { - pL = holder.view.getPaddingLeft(); - pT = holder.view.getPaddingTop(); - pR = holder.view.getPaddingRight(); - pB = holder.view.getPaddingBottom(); - } - - holder.setChecked(item.getChecked()); - - if (item.getOnChangeAction() != null || item.getOnClickAction() != null || item.getOnLongClickAction() != null) { - TypedValue outValue = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true); - holder.view.setBackgroundResource(outValue.resourceId); - } else { - holder.view.setBackgroundResource(0); - } - holder.setOnClickAction(item.getOnClickAction()); - holder.setOnLongClickAction(item.getOnLongClickAction()); - holder.setOnChangeAction(item.getOnChangeAction()); - - if (Build.VERSION.SDK_INT < 21) { - holder.view.setPadding(pL, pT, pR, pB); - } - } - - public static MaterialAboutItemViewHolder getViewHolder(View view) { - return new MaterialAboutActionSwitchItemViewHolder(view); - } - - public static class MaterialAboutActionSwitchItemViewHolder extends MaterialAboutItemViewHolder implements View.OnClickListener, View.OnLongClickListener, CompoundButton.OnCheckedChangeListener { - public final View view; - public final ImageView icon; - public final TextView text; - public final TextView subText; - public final SwitchCompat switchView; - private MaterialAboutItemOnClickAction onClickAction; - private MaterialAboutItemOnClickAction onLongClickAction; - private MaterialAboutItemOnChangeAction onChangeAction; - private MaterialAboutActionSwitchItem switchItem; - - MaterialAboutActionSwitchItemViewHolder(View view) { - super(view); - this.view = view.findViewById(R.id.mal_action_root); - icon = view.findViewById(R.id.mal_item_image); - text = view.findViewById(R.id.mal_item_text); - subText = view.findViewById(R.id.mal_action_item_subtext); - switchView = view.findViewById(R.id.mal_switch); - } - - public void setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - view.setOnClickListener(onClickAction != null ? this : null); - } - - public void setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - view.setOnLongClickListener(onLongClickAction != null ? this : null); - } - - public void setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - switchView.setOnCheckedChangeListener(this); - } - - public void setChecked(boolean checked) { - switchView.setChecked(checked); - switchItem.checked = checked; - updateSubText(checked); - } - - public void updateSubText(boolean checked) { - if (checked && switchItem.subTextChecked != null) { - subText.setText(switchItem.subTextChecked); - } - else if (checked && switchItem.subTextCheckedRes != 0) { - subText.setText(switchItem.subTextCheckedRes); - } - else if (switchItem.subText != null) { - subText.setText(switchItem.subText); - } - else if (switchItem.subTextRes != 0) { - subText.setText(switchItem.subTextRes); - } - } - - @Override - public void onClick(View v) { - if (onClickAction != null) { - onClickAction.onClick(); - } - } - - @Override - public boolean onLongClick(View v) { - if (onLongClickAction != null) { - onLongClickAction.onClick(); - return true; - } - return false; - } - - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - updateSubText(isChecked); - if (onChangeAction != null) { - if (!onChangeAction.onChange(isChecked, switchItem.getTag())) { - setChecked(!isChecked); - } - else { - switchItem.checked = isChecked; - } - } - else { - setChecked(!isChecked); - } - } - } - - @Override - public int getType() { - return ViewTypeManager.ItemType.ACTION_SWITCH_ITEM; - } - - @Override - public String getDetailString() { - return "MaterialAboutActionSwitchItem{" + - "text=" + text + - ", textRes=" + textRes + - ", subText=" + subText + - ", subTextRes=" + subTextRes + - ", subTextChecked=" + subTextChecked + - ", subTextCheckedRes=" + subTextCheckedRes + - ", icon=" + icon + - ", iconRes=" + iconRes + - ", showIcon=" + showIcon + - ", iconGravity=" + iconGravity + - ", checked=" + checked + - ", tag=" + tag + - ", onClickAction=" + onClickAction + - ", onLongClickAction=" + onLongClickAction + - ", onChangeAction=" + onChangeAction + - '}'; - } - - public MaterialAboutActionSwitchItem(MaterialAboutActionSwitchItem item) { - this.id = item.getId(); - this.text = item.getText(); - this.textRes = item.getTextRes(); - this.subText = item.getSubText(); - this.subTextRes = item.getSubTextRes(); - this.subTextChecked = item.getSubTextChecked(); - this.subTextCheckedRes = item.getSubTextCheckedRes(); - this.icon = item.getIcon(); - this.iconRes = item.getIconRes(); - this.showIcon = item.showIcon; - this.iconGravity = item.iconGravity; - this.checked = item.checked; - this.tag = item.tag; - this.onClickAction = item.onClickAction; - this.onLongClickAction = item.onLongClickAction; - this.onChangeAction = item.onChangeAction; - } - - @Override - public MaterialAboutItem clone() { - return new MaterialAboutActionSwitchItem(this); - } - - public int getTag() { - return tag; - } - public MaterialAboutActionSwitchItem setTag(int tag) { - this.tag = tag; - return this; - } - - public CharSequence getText() { - return text; - } - public MaterialAboutActionSwitchItem setText(CharSequence text) { - this.textRes = 0; - this.text = text; - return this; - } - - public int getTextRes() { - return textRes; - } - - public MaterialAboutActionSwitchItem setTextRes(int textRes) { - this.text = null; - this.textRes = textRes; - return this; - } - - public CharSequence getSubText() { - return subText; - } - - public MaterialAboutActionSwitchItem setSubText(CharSequence subText) { - this.subTextRes = 0; - this.subText = subText; - return this; - } - - public int getSubTextRes() { - return subTextRes; - } - - public MaterialAboutActionSwitchItem setSubTextRes(int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public CharSequence getSubTextChecked() { - return subTextChecked; - } - - public MaterialAboutActionSwitchItem setSubTextChecked(CharSequence subTextChecked) { - this.subTextCheckedRes = 0; - this.subTextChecked = subTextChecked; - return this; - } - - public int getSubTextCheckedRes() { - return subTextCheckedRes; - } - - public MaterialAboutActionSwitchItem setSubTextCheckedRes(int subTextCheckedRes) { - this.subTextChecked = null; - this.subTextCheckedRes = subTextCheckedRes; - return this; - } - - public Drawable getIcon() { - return icon; - } - - public MaterialAboutActionSwitchItem setIcon(Drawable icon) { - this.iconRes = 0; - this.icon = icon; - return this; - } - - public int getIconRes() { - return iconRes; - } - - public MaterialAboutActionSwitchItem setIconRes(int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public boolean shouldShowIcon() { - return showIcon; - } - - public MaterialAboutActionSwitchItem setShouldShowIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - @IconGravity - public int getIconGravity() { - return iconGravity; - } - - public MaterialAboutActionSwitchItem setIconGravity(int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public boolean getChecked() { - return checked; - } - - public MaterialAboutActionSwitchItem setChecked(boolean checked) { - this.checked = checked; - return this; - } - - public MaterialAboutItemOnClickAction getOnClickAction() { - return onClickAction; - } - - public MaterialAboutActionSwitchItem setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public MaterialAboutItemOnClickAction getOnLongClickAction() { - return onLongClickAction; - } - - public MaterialAboutActionSwitchItem setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - - public MaterialAboutItemOnChangeAction getOnChangeAction() { - return onChangeAction; - } - - public MaterialAboutActionSwitchItem setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - return this; - } - - @Retention(RetentionPolicy.SOURCE) - @IntDef({GRAVITY_TOP, GRAVITY_MIDDLE, GRAVITY_BOTTOM}) - public @interface IconGravity { - } - - public static class Builder { - - MaterialAboutItemOnClickAction onClickAction = null; - MaterialAboutItemOnClickAction onLongClickAction = null; - MaterialAboutItemOnChangeAction onChangeAction = null; - private CharSequence text = null; - @StringRes - private int textRes = 0; - private CharSequence subText = null; - @StringRes - private int subTextRes = 0; - private CharSequence subTextChecked = null; - @StringRes - private int subTextCheckedRes = 0; - private Drawable icon = null; - @DrawableRes - private int iconRes = 0; - private boolean showIcon = true; - @IconGravity - private int iconGravity = GRAVITY_MIDDLE; - private boolean checked = false; - private int tag = -1; - - public Builder tag(int tag) { - this.tag = tag; - return this; - } - - public Builder text(CharSequence text) { - this.text = text; - this.textRes = 0; - return this; - } - - public Builder text(@StringRes int text) { - this.textRes = text; - this.text = null; - return this; - } - - public Builder subText(CharSequence subText) { - this.subText = subText; - this.subTextRes = 0; - return this; - } - - public Builder subText(@StringRes int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public Builder subTextHtml(String subTextHtml) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - this.subText = Html.fromHtml(subTextHtml, Html.FROM_HTML_MODE_LEGACY); - } else { - //noinspection deprecation - this.subText = Html.fromHtml(subTextHtml); - } - this.subTextRes = 0; - return this; - } - - public Builder subTextChecked(CharSequence subTextChecked) { - this.subTextChecked = subTextChecked; - this.subTextCheckedRes = 0; - return this; - } - - public Builder subTextChecked(@StringRes int subTextCheckedRes) { - this.subTextChecked = null; - this.subTextCheckedRes = subTextCheckedRes; - return this; - } - - public Builder subTextCheckedHtml(String subTextCheckedHtml) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - this.subTextChecked = Html.fromHtml(subTextCheckedHtml, Html.FROM_HTML_MODE_LEGACY); - } else { - //noinspection deprecation - this.subTextChecked = Html.fromHtml(subTextCheckedHtml); - } - this.subTextCheckedRes = 0; - return this; - } - - public Builder icon(Drawable icon) { - this.icon = icon; - this.iconRes = 0; - return this; - } - - public Builder icon(@DrawableRes int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public Builder showIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - public Builder setIconGravity(@IconGravity int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public Builder setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public Builder setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - - public Builder setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - return this; - } - - public Builder checked(boolean isChecked) { - this.checked = isChecked; - return this; - } - - public MaterialAboutActionSwitchItem build() { - return new MaterialAboutActionSwitchItem(this); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutCheckboxItem.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutCheckboxItem.java deleted file mode 100644 index 16a6cd45..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutCheckboxItem.java +++ /dev/null @@ -1,538 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.os.Build; -import androidx.annotation.DrawableRes; -import androidx.annotation.IntDef; -import androidx.annotation.StringRes; -import android.text.Html; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.View; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import static android.view.View.GONE; - -public class MaterialAboutCheckboxItem extends MaterialAboutItem { - - public static final int GRAVITY_TOP = 0; - public static final int GRAVITY_MIDDLE = 1; - public static final int GRAVITY_BOTTOM = 2; - private CharSequence text = null; - private int textRes = 0; - private CharSequence subText = null; - private int subTextRes = 0; - private CharSequence subTextChecked = null; - private int subTextCheckedRes = 0; - private Drawable icon = null; - private int iconRes = 0; - private boolean showIcon = true; - private int iconGravity = GRAVITY_MIDDLE; - private boolean checked = false; - private int tag = -1; - private MaterialAboutItemOnChangeAction onChangeAction = null; - - private MaterialAboutCheckboxItem(Builder builder) { - super(); - this.text = builder.text; - this.textRes = builder.textRes; - - this.subText = builder.subText; - this.subTextRes = builder.subTextRes; - - this.subTextChecked = builder.subTextChecked; - this.subTextCheckedRes = builder.subTextCheckedRes; - - this.icon = builder.icon; - this.iconRes = builder.iconRes; - - this.showIcon = builder.showIcon; - - this.iconGravity = builder.iconGravity; - - this.checked = builder.checked; - - this.tag = builder.tag; - - this.onChangeAction = builder.onChangeAction; - } - - public MaterialAboutCheckboxItem(CharSequence text, CharSequence subText, Drawable icon, MaterialAboutItemOnChangeAction onChangeAction) { - this.text = text; - this.subText = subText; - this.icon = icon; - this.onChangeAction = onChangeAction; - } - - public MaterialAboutCheckboxItem(CharSequence text, CharSequence subText, Drawable icon) { - this.text = text; - this.subText = subText; - this.icon = icon; - } - - public MaterialAboutCheckboxItem(int textRes, int subTextRes, int iconRes, MaterialAboutItemOnChangeAction onChangeAction) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - this.onChangeAction = onChangeAction; - } - - public MaterialAboutCheckboxItem(int textRes, int subTextRes, int iconRes) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - } - - public static MaterialAboutItemViewHolder getViewHolder(View view) { - return new MaterialAboutCheckboxItemViewHolder(view); - } - - public static void setupItem(MaterialAboutCheckboxItemViewHolder holder, MaterialAboutCheckboxItem item, Context context) { - holder.switchItem = item; - - CharSequence text = item.getText(); - int textRes = item.getTextRes(); - - holder.text.setVisibility(View.VISIBLE); - if (text != null) { - holder.text.setText(text); - } else if (textRes != 0) { - holder.text.setText(textRes); - } else { - holder.text.setVisibility(GONE); - } - - CharSequence subText = item.getSubText(); - int subTextRes = item.getSubTextRes(); - - holder.subText.setVisibility(View.VISIBLE); - if (subText != null) { - holder.subText.setText(subText); - } else if (subTextRes != 0) { - holder.subText.setText(subTextRes); - } else { - holder.subText.setVisibility(GONE); - } - - if (item.shouldShowIcon()) { - holder.icon.setVisibility(View.VISIBLE); - Drawable drawable = item.getIcon(); - int drawableRes = item.getIconRes(); - if (drawable != null) { - holder.icon.setImageDrawable(drawable); - } else if (drawableRes != 0) { - holder.icon.setImageResource(drawableRes); - } - } else { - holder.icon.setVisibility(GONE); - } - - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) holder.icon.getLayoutParams(); - switch (item.getIconGravity()) { - case MaterialAboutCheckboxItem.GRAVITY_TOP: - params.gravity = Gravity.TOP; - break; - case MaterialAboutCheckboxItem.GRAVITY_MIDDLE: - params.gravity = Gravity.CENTER_VERTICAL; - break; - case MaterialAboutCheckboxItem.GRAVITY_BOTTOM: - params.gravity = Gravity.BOTTOM; - break; - } - holder.icon.setLayoutParams(params); - - int pL = 0, pT = 0, pR = 0, pB = 0; - if (Build.VERSION.SDK_INT < 21) { - pL = holder.view.getPaddingLeft(); - pT = holder.view.getPaddingTop(); - pR = holder.view.getPaddingRight(); - pB = holder.view.getPaddingBottom(); - } - - - if (item.getOnChangeAction() != null) { - TypedValue outValue = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true); - holder.view.setBackgroundResource(outValue.resourceId); - } else { - holder.view.setBackgroundResource(0); - } - holder.setOnChangeAction(item.getOnChangeAction()); - - if (Build.VERSION.SDK_INT < 21) { - holder.view.setPadding(pL, pT, pR, pB); - } - } - - @Override - public int getType() { - return ViewTypeManager.ItemType.CHECKBOX_ITEM; - } - - @Override - public String getDetailString() { - return "MaterialAboutCheckboxItem{" + - "text=" + text + - ", textRes=" + textRes + - ", subText=" + subText + - ", subTextRes=" + subTextRes + - ", subTextChecked=" + subTextChecked + - ", subTextCheckedRes=" + subTextCheckedRes + - ", icon=" + icon + - ", iconRes=" + iconRes + - ", showIcon=" + showIcon + - ", iconGravity=" + iconGravity + - ", checked=" + checked + - ", tag=" + tag + - ", onChangeAction=" + onChangeAction + - '}'; - } - - public MaterialAboutCheckboxItem(MaterialAboutCheckboxItem item) { - this.id = item.getId(); - this.text = item.getText(); - this.textRes = item.getTextRes(); - this.subText = item.getSubText(); - this.subTextRes = item.getSubTextRes(); - this.subTextChecked = item.getSubTextChecked(); - this.subTextCheckedRes = item.getSubTextCheckedRes(); - this.icon = item.getIcon(); - this.iconRes = item.getIconRes(); - this.showIcon = item.showIcon; - this.iconGravity = item.iconGravity; - this.checked = item.checked; - this.tag = item.tag; - this.onChangeAction = item.onChangeAction; - } - - @Override - public MaterialAboutItem clone() { - return new MaterialAboutCheckboxItem(this); - } - - public int getTag() { - return tag; - } - public MaterialAboutCheckboxItem setTag(int tag) { - this.tag = tag; - return this; - } - - public CharSequence getText() { - return text; - } - public MaterialAboutCheckboxItem setText(CharSequence text) { - this.textRes = 0; - this.text = text; - return this; - } - - public int getTextRes() { - return textRes; - } - - public MaterialAboutCheckboxItem setTextRes(int textRes) { - this.text = null; - this.textRes = textRes; - return this; - } - - public CharSequence getSubText() { - return subText; - } - - public MaterialAboutCheckboxItem setSubText(CharSequence subText) { - this.subTextRes = 0; - this.subText = subText; - return this; - } - - public int getSubTextRes() { - return subTextRes; - } - - public MaterialAboutCheckboxItem setSubTextRes(int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public CharSequence getSubTextChecked() { - return subTextChecked; - } - - public MaterialAboutCheckboxItem setSubTextChecked(CharSequence subTextChecked) { - this.subTextCheckedRes = 0; - this.subTextChecked = subTextChecked; - return this; - } - - public int getSubTextCheckedRes() { - return subTextCheckedRes; - } - - public MaterialAboutCheckboxItem setSubTextCheckedRes(int subTextCheckedRes) { - this.subTextChecked = null; - this.subTextCheckedRes = subTextCheckedRes; - return this; - } - - public Drawable getIcon() { - return icon; - } - - public MaterialAboutCheckboxItem setIcon(Drawable icon) { - this.iconRes = 0; - this.icon = icon; - return this; - } - - public int getIconRes() { - return iconRes; - } - - public MaterialAboutCheckboxItem setIconRes(int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public boolean shouldShowIcon() { - return showIcon; - } - - public MaterialAboutCheckboxItem setShouldShowIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - @IconGravity - public int getIconGravity() { - return iconGravity; - } - - public MaterialAboutCheckboxItem setIconGravity(int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public boolean getChecked() { - return checked; - } - - public MaterialAboutCheckboxItem setChecked(boolean checked) { - this.checked = checked; - return this; - } - - public MaterialAboutItemOnChangeAction getOnChangeAction() { - return onChangeAction; - } - - public MaterialAboutCheckboxItem setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - return this; - } - - @Retention(RetentionPolicy.SOURCE) - @IntDef({GRAVITY_TOP, GRAVITY_MIDDLE, GRAVITY_BOTTOM}) - public @interface IconGravity { - } - - public static class MaterialAboutCheckboxItemViewHolder extends MaterialAboutItemViewHolder implements View.OnClickListener, CompoundButton.OnCheckedChangeListener { - public final View view; - public final ImageView icon; - public final TextView text; - public final TextView subText; - public final CheckBox checkBox; - private MaterialAboutItemOnChangeAction onChangeAction; - private MaterialAboutCheckboxItem switchItem; - - MaterialAboutCheckboxItemViewHolder(View view) { - super(view); - this.view = view; - icon = view.findViewById(R.id.mal_item_image); - text = view.findViewById(R.id.mal_item_text); - subText = view.findViewById(R.id.mal_action_item_subtext); - checkBox = view.findViewById(R.id.mal_checkbox); - } - - public void setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - view.setOnClickListener(onChangeAction != null ? this : null); - checkBox.setOnCheckedChangeListener(this); - } - - public void setChecked(boolean checked) { - checkBox.setOnCheckedChangeListener(null); - checkBox.setChecked(checked); - checkBox.setOnCheckedChangeListener(this); - updateSubText(checked); - } - - public void updateSubText(boolean checked) { - if (checked && switchItem.subTextChecked != null) { - subText.setText(switchItem.subTextChecked); - } - else if (checked && switchItem.subTextCheckedRes != 0) { - subText.setText(switchItem.subTextCheckedRes); - } - else if (switchItem.subText != null) { - subText.setText(switchItem.subText); - } - else if (switchItem.subTextRes != 0) { - subText.setText(switchItem.subTextRes); - } - } - - @Override - public void onClick(View v) { - checkBox.toggle(); - } - - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - updateSubText(isChecked); - if (onChangeAction != null) { - if (!onChangeAction.onChange(isChecked, switchItem.getTag())) - setChecked(!isChecked); - } - else { - setChecked(!isChecked); - } - } - } - - public static class Builder { - - MaterialAboutItemOnChangeAction onChangeAction = null; - private CharSequence text = null; - @StringRes - private int textRes = 0; - private CharSequence subText = null; - @StringRes - private int subTextRes = 0; - private CharSequence subTextChecked = null; - @StringRes - private int subTextCheckedRes = 0; - private Drawable icon = null; - @DrawableRes - private int iconRes = 0; - private boolean showIcon = true; - @IconGravity - private int iconGravity = GRAVITY_MIDDLE; - private boolean checked = false; - private int tag = -1; - - public Builder tag(int tag) { - this.tag = tag; - return this; - } - - public Builder text(CharSequence text) { - this.text = text; - this.textRes = 0; - return this; - } - - public Builder text(@StringRes int text) { - this.textRes = text; - this.text = null; - return this; - } - - public Builder subText(CharSequence subText) { - this.subText = subText; - this.subTextRes = 0; - return this; - } - - public Builder subText(@StringRes int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public Builder subTextHtml(String subTextHtml) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - this.subText = Html.fromHtml(subTextHtml, Html.FROM_HTML_MODE_LEGACY); - } else { - //noinspection deprecation - this.subText = Html.fromHtml(subTextHtml); - } - this.subTextRes = 0; - return this; - } - - public Builder subTextChecked(CharSequence subTextChecked) { - this.subTextChecked = subTextChecked; - this.subTextCheckedRes = 0; - return this; - } - - public Builder subTextChecked(@StringRes int subTextCheckedRes) { - this.subTextChecked = null; - this.subTextCheckedRes = subTextCheckedRes; - return this; - } - - public Builder subTextCheckedHtml(String subTextCheckedHtml) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - this.subTextChecked = Html.fromHtml(subTextCheckedHtml, Html.FROM_HTML_MODE_LEGACY); - } else { - //noinspection deprecation - this.subTextChecked = Html.fromHtml(subTextCheckedHtml); - } - this.subTextCheckedRes = 0; - return this; - } - - public Builder icon(Drawable icon) { - this.icon = icon; - this.iconRes = 0; - return this; - } - - public Builder icon(@DrawableRes int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public Builder showIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - public Builder setIconGravity(@IconGravity int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public Builder setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - return this; - } - - public Builder checked(boolean isChecked) { - this.checked = isChecked; - return this; - } - - public MaterialAboutCheckboxItem build() { - return new MaterialAboutCheckboxItem(this); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItem.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItem.java deleted file mode 100644 index 2d6a5f48..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItem.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - -import java.util.UUID; - -public abstract class MaterialAboutItem { - - public String id = "NO-UUID"; - - public MaterialAboutItem() { - this.id = UUID.randomUUID().toString(); - } - - public String getId() { - return id; - } - - public abstract int getType(); - - public abstract String getDetailString(); - - public abstract MaterialAboutItem clone(); - -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItemOnChangeAction.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItemOnChangeAction.java deleted file mode 100644 index 836883db..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItemOnChangeAction.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - -public interface MaterialAboutItemOnChangeAction { - boolean onChange(boolean isChecked, int tag); -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItemOnClickAction.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItemOnClickAction.java deleted file mode 100644 index ca1cd610..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItemOnClickAction.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - -public interface MaterialAboutItemOnClickAction { - void onClick(); -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutProfileItem.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutProfileItem.java deleted file mode 100644 index aeb4d4fe..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutProfileItem.java +++ /dev/null @@ -1,352 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.os.Build; -import androidx.annotation.DrawableRes; -import androidx.annotation.StringRes; - -import android.util.Log; -import android.util.TypedValue; -import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import static android.view.View.GONE; - -public class MaterialAboutProfileItem extends MaterialAboutItem { - - private CharSequence text = null; - private int textRes = 0; - private CharSequence desc = null; - private int descRes = 0; - private Drawable icon = null; - private int iconRes = 0; - private MaterialAboutItemOnClickAction onClickAction = null; - private MaterialAboutItemOnClickAction onLongClickAction = null; - - private MaterialAboutProfileItem(MaterialAboutProfileItem.Builder builder) { - super(); - this.text = builder.text; - this.textRes = builder.textRes; - - this.desc = builder.desc; - this.descRes = builder.descRes; - - this.icon = builder.icon; - this.iconRes = builder.iconRes; - - this.onClickAction = builder.onClickAction; - this.onLongClickAction = builder.onLongClickAction; - } - - public MaterialAboutProfileItem(CharSequence text, CharSequence desc, Drawable icon) { - this.text = text; - this.desc = desc; - this.icon = icon; - } - - public MaterialAboutProfileItem(int textRes, int descRes, int iconRes) { - this.textRes = textRes; - this.descRes = descRes; - this.iconRes = iconRes; - } - - public static MaterialAboutItemViewHolder getViewHolder(View view) { - return new MaterialAboutProfileItem.MaterialAboutProfileItemViewHolder(view); - } - - public static void setupItem(MaterialAboutProfileItemViewHolder holder, MaterialAboutProfileItem item, Context context) { - - CharSequence text = item.getText(); - int textRes = item.getTextRes(); - - holder.text.setVisibility(View.VISIBLE); - if (text != null) { - holder.text.setText(text); - } else if (textRes != 0) { - holder.text.setText(textRes); - } else { - holder.text.setVisibility(GONE); - } - - CharSequence desc = item.getDesc(); - int descRes = item.getDescRes(); - - holder.desc.setVisibility(View.VISIBLE); - if (desc != null) { - holder.desc.setText(desc); - } else if (descRes != 0) { - holder.desc.setText(descRes); - } else { - holder.desc.setVisibility(GONE); - } - - Drawable drawable = item.getIcon(); - int drawableRes = item.getIconRes(); - if (drawable != null) { - holder.icon.setImageDrawable(drawable); - } else if (drawableRes != 0) { - holder.icon.setImageResource(drawableRes); - } - - int pL = 0, pT = 0, pR = 0, pB = 0; - if (Build.VERSION.SDK_INT < 21) { - pL = holder.view.getPaddingLeft(); - pT = holder.view.getPaddingTop(); - pR = holder.view.getPaddingRight(); - pB = holder.view.getPaddingBottom(); - } - - if (item.getOnClickAction() != null || item.getOnLongClickAction() != null) { - TypedValue outValue = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true); - holder.view.setBackgroundResource(outValue.resourceId); - } else { - holder.view.setBackgroundResource(0); - } - holder.setOnClickAction(item.getOnClickAction()); - holder.setOnLongClickAction(item.getOnLongClickAction()); - - if (Build.VERSION.SDK_INT < 21) { - holder.view.setPadding(pL, pT, pR, pB); - } - } - - @Override - public int getType() { - return ViewTypeManager.ItemType.PROFILE_ITEM; - } - - @Override - public String getDetailString() { - return "MaterialAboutProfileItem{" + - "text=" + text + - ", textRes=" + textRes + - ", desc=" + desc + - ", descRes=" + descRes + - ", icon=" + icon + - ", iconRes=" + iconRes + - ", onClickAction=" + onClickAction + - ", onLongClickAction=" + onLongClickAction + - '}'; - } - - public MaterialAboutProfileItem(MaterialAboutProfileItem item) { - this.id = item.getId(); - this.text = item.getText(); - this.textRes = item.getTextRes(); - this.desc = item.getDesc(); - this.descRes = item.getDescRes(); - this.icon = item.getIcon(); - this.iconRes = item.getIconRes(); - this.onClickAction = item.getOnClickAction(); - this.onLongClickAction = item.getOnLongClickAction(); - } - - @Override - public MaterialAboutProfileItem clone() { - return new MaterialAboutProfileItem(this); - } - - public CharSequence getText() { - return text; - } - - public MaterialAboutProfileItem setText(CharSequence text) { - this.textRes = 0; - this.text = text; - return this; - } - - public int getTextRes() { - return textRes; - } - - public MaterialAboutProfileItem setTextRes(int textRes) { - this.text = null; - this.textRes = textRes; - return this; - } - - public CharSequence getDesc() { - return desc; - } - - public MaterialAboutProfileItem setDesc(CharSequence desc) { - this.descRes = 0; - this.desc = desc; - return this; - } - - public int getDescRes() { - return descRes; - } - - public MaterialAboutProfileItem setDescRes(int descRes) { - this.desc = null; - this.descRes = textRes; - return this; - } - - public Drawable getIcon() { - return icon; - } - - public MaterialAboutProfileItem setIcon(Drawable icon) { - this.iconRes = 0; - this.icon = icon; - return this; - } - - public int getIconRes() { - return iconRes; - } - - public MaterialAboutProfileItem setIconRes(int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public MaterialAboutItemOnClickAction getOnClickAction() { - return onClickAction; - } - - public MaterialAboutProfileItem setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public MaterialAboutItemOnClickAction getOnLongClickAction() { - return onLongClickAction; - } - - public MaterialAboutProfileItem setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - public static class MaterialAboutProfileItemViewHolder extends MaterialAboutItemViewHolder implements View.OnClickListener, View.OnLongClickListener { - public final View view; - public final ImageView icon; - public final TextView text; - public final TextView desc; - private MaterialAboutItemOnClickAction onClickAction; - private MaterialAboutItemOnClickAction onLongClickAction; - - MaterialAboutProfileItemViewHolder(View view) { - super(view); - this.view = view; - icon = (ImageView) view.findViewById(R.id.mal_item_image); - text = (TextView) view.findViewById(R.id.mal_item_text); - desc = (TextView) view.findViewById(R.id.mal_item_desc); - } - - public void setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - if (onClickAction != null) { - view.setOnClickListener(this); - } else { - view.setClickable(false); - } - } - - public void setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - if (onLongClickAction != null) { - view.setOnLongClickListener(this); - } else { - view.setLongClickable(false); - } - } - - @Override - public void onClick(View v) { - if (onClickAction != null) { - onClickAction.onClick(); - } - } - - @Override - public boolean onLongClick(View v) { - if (onLongClickAction != null) { - onLongClickAction.onClick(); - return true; - } - return false; - } - } - - public static class Builder { - - MaterialAboutItemOnClickAction onClickAction = null; - MaterialAboutItemOnClickAction onLongClickAction = null; - private CharSequence text = null; - @StringRes - private int textRes = 0; - private CharSequence desc = null; - @StringRes - private int descRes = 0; - private Drawable icon = null; - @DrawableRes - private int iconRes = 0; - - public MaterialAboutProfileItem.Builder text(CharSequence text) { - this.text = text; - this.textRes = 0; - return this; - } - - - public MaterialAboutProfileItem.Builder text(@StringRes int text) { - this.textRes = text; - this.text = null; - return this; - } - - public MaterialAboutProfileItem.Builder desc(CharSequence desc) { - this.desc = desc; - this.descRes = 0; - return this; - } - - - public MaterialAboutProfileItem.Builder desc(@StringRes int desc) { - this.descRes = desc; - this.desc = null; - return this; - } - - public MaterialAboutProfileItem.Builder icon(Drawable icon) { - this.icon = icon; - this.iconRes = 0; - return this; - } - - - public MaterialAboutProfileItem.Builder icon(@DrawableRes int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public MaterialAboutProfileItem.Builder setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public MaterialAboutProfileItem.Builder setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - - public MaterialAboutProfileItem build() { - return new MaterialAboutProfileItem(this); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutSwitchItem.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutSwitchItem.java deleted file mode 100644 index 4ce55683..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutSwitchItem.java +++ /dev/null @@ -1,548 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.os.Build; -import androidx.annotation.DrawableRes; -import androidx.annotation.IntDef; -import androidx.annotation.StringRes; -import androidx.appcompat.widget.SwitchCompat; - -import android.text.Html; -import android.util.Log; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.Switch; -import android.widget.TextView; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import static android.view.View.GONE; - -public class MaterialAboutSwitchItem extends MaterialAboutItem { - - public static final int GRAVITY_TOP = 0; - public static final int GRAVITY_MIDDLE = 1; - public static final int GRAVITY_BOTTOM = 2; - private CharSequence text = null; - private int textRes = 0; - private CharSequence subText = null; - private int subTextRes = 0; - private CharSequence subTextChecked = null; - private int subTextCheckedRes = 0; - private Drawable icon = null; - private int iconRes = 0; - private boolean showIcon = true; - private int iconGravity = GRAVITY_MIDDLE; - private boolean checked = false; - private int tag = -1; - private MaterialAboutItemOnChangeAction onChangeAction = null; - - private MaterialAboutSwitchItem(Builder builder) { - super(); - this.text = builder.text; - this.textRes = builder.textRes; - - this.subText = builder.subText; - this.subTextRes = builder.subTextRes; - - this.subTextChecked = builder.subTextChecked; - this.subTextCheckedRes = builder.subTextCheckedRes; - - this.icon = builder.icon; - this.iconRes = builder.iconRes; - - this.showIcon = builder.showIcon; - - this.iconGravity = builder.iconGravity; - - this.checked = builder.checked; - - this.tag = builder.tag; - - this.onChangeAction = builder.onChangeAction; - } - - public MaterialAboutSwitchItem(CharSequence text, CharSequence subText, Drawable icon, MaterialAboutItemOnChangeAction onChangeAction) { - this.text = text; - this.subText = subText; - this.icon = icon; - this.onChangeAction = onChangeAction; - } - - public MaterialAboutSwitchItem(CharSequence text, CharSequence subText, Drawable icon) { - this.text = text; - this.subText = subText; - this.icon = icon; - } - - public MaterialAboutSwitchItem(int textRes, int subTextRes, int iconRes, MaterialAboutItemOnChangeAction onChangeAction) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - this.onChangeAction = onChangeAction; - } - - public MaterialAboutSwitchItem(int textRes, int subTextRes, int iconRes) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - } - - public static void setupItem(MaterialAboutSwitchItemViewHolder holder, MaterialAboutSwitchItem item, Context context) { - holder.switchItem = item; - - CharSequence text = item.getText(); - int textRes = item.getTextRes(); - - holder.text.setVisibility(View.VISIBLE); - if (text != null) { - holder.text.setText(text); - } else if (textRes != 0) { - holder.text.setText(textRes); - } else { - holder.text.setVisibility(GONE); - } - - CharSequence subText = item.getSubText(); - int subTextRes = item.getSubTextRes(); - - holder.subText.setVisibility(View.VISIBLE); - if (subText != null) { - holder.subText.setText(subText); - } else if (subTextRes != 0) { - holder.subText.setText(subTextRes); - } else { - holder.subText.setVisibility(GONE); - } - - if (item.shouldShowIcon()) { - holder.icon.setVisibility(View.VISIBLE); - Drawable drawable = item.getIcon(); - int drawableRes = item.getIconRes(); - if (drawable != null) { - holder.icon.setImageDrawable(drawable); - } else if (drawableRes != 0) { - holder.icon.setImageResource(drawableRes); - } - } else { - holder.icon.setVisibility(GONE); - } - - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) holder.icon.getLayoutParams(); - switch (item.getIconGravity()) { - case MaterialAboutSwitchItem.GRAVITY_TOP: - params.gravity = Gravity.TOP; - break; - case MaterialAboutSwitchItem.GRAVITY_MIDDLE: - params.gravity = Gravity.CENTER_VERTICAL; - break; - case MaterialAboutSwitchItem.GRAVITY_BOTTOM: - params.gravity = Gravity.BOTTOM; - break; - } - holder.icon.setLayoutParams(params); - - int pL = 0, pT = 0, pR = 0, pB = 0; - if (Build.VERSION.SDK_INT < 21) { - pL = holder.view.getPaddingLeft(); - pT = holder.view.getPaddingTop(); - pR = holder.view.getPaddingRight(); - pB = holder.view.getPaddingBottom(); - } - - holder.setChecked(item.getChecked()); - - if (item.getOnChangeAction() != null) { - TypedValue outValue = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true); - holder.view.setBackgroundResource(outValue.resourceId); - } else { - holder.view.setBackgroundResource(0); - } - holder.setOnChangeAction(item.getOnChangeAction()); - - if (Build.VERSION.SDK_INT < 21) { - holder.view.setPadding(pL, pT, pR, pB); - } - } - - public static MaterialAboutItemViewHolder getViewHolder(View view) { - return new MaterialAboutSwitchItemViewHolder(view); - } - - public static class MaterialAboutSwitchItemViewHolder extends MaterialAboutItemViewHolder implements View.OnClickListener, CompoundButton.OnCheckedChangeListener { - public final View view; - public final ImageView icon; - public final TextView text; - public final TextView subText; - public final SwitchCompat switchView; - private MaterialAboutItemOnChangeAction onChangeAction; - private MaterialAboutSwitchItem switchItem; - - MaterialAboutSwitchItemViewHolder(View view) { - super(view); - this.view = view; - icon = view.findViewById(R.id.mal_item_image); - text = view.findViewById(R.id.mal_item_text); - subText = view.findViewById(R.id.mal_action_item_subtext); - switchView = view.findViewById(R.id.mal_switch); - } - - public void setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - view.setOnClickListener(onChangeAction != null ? this : null); - switchView.setOnCheckedChangeListener(this); - } - - public void setChecked(boolean checked) { - switchView.setOnCheckedChangeListener(null); - switchView.setChecked(checked); - switchView.setOnCheckedChangeListener(this); - switchItem.setChecked(checked); - updateSubText(checked); - } - - public void updateSubText(boolean checked) { - if (checked && switchItem.subTextChecked != null) { - subText.setText(switchItem.subTextChecked); - } - else if (checked && switchItem.subTextCheckedRes != 0) { - subText.setText(switchItem.subTextCheckedRes); - } - else if (switchItem.subText != null) { - subText.setText(switchItem.subText); - } - else if (switchItem.subTextRes != 0) { - subText.setText(switchItem.subTextRes); - } - } - - @Override - public void onClick(View v) { - switchView.toggle(); - } - - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - updateSubText(isChecked); - if (onChangeAction != null) { - if (!onChangeAction.onChange(isChecked, switchItem.getTag())) { - setChecked(!isChecked); - } - else { - switchItem.setChecked(isChecked); - } - } - else { - setChecked(!isChecked); - } - } - } - - @Override - public int getType() { - return ViewTypeManager.ItemType.SWITCH_ITEM; - } - - @Override - public String getDetailString() { - return "MaterialAboutSwitchItem{" + - "text=" + text + - ", textRes=" + textRes + - ", subText=" + subText + - ", subTextRes=" + subTextRes + - ", subTextChecked=" + subTextChecked + - ", subTextCheckedRes=" + subTextCheckedRes + - ", icon=" + icon + - ", iconRes=" + iconRes + - ", showIcon=" + showIcon + - ", iconGravity=" + iconGravity + - ", checked=" + checked + - ", tag=" + tag + - ", onChangeAction=" + onChangeAction + - '}'; - } - - public MaterialAboutSwitchItem(MaterialAboutSwitchItem item) { - this.id = item.getId(); - this.text = item.getText(); - this.textRes = item.getTextRes(); - this.subText = item.getSubText(); - this.subTextRes = item.getSubTextRes(); - this.subTextChecked = item.getSubTextChecked(); - this.subTextCheckedRes = item.getSubTextCheckedRes(); - this.icon = item.getIcon(); - this.iconRes = item.getIconRes(); - this.showIcon = item.showIcon; - this.iconGravity = item.iconGravity; - this.checked = item.checked; - this.tag = item.tag; - this.onChangeAction = item.onChangeAction; - } - - @Override - public MaterialAboutItem clone() { - return new MaterialAboutSwitchItem(this); - } - - public int getTag() { - return tag; - } - public MaterialAboutSwitchItem setTag(int tag) { - this.tag = tag; - return this; - } - - public CharSequence getText() { - return text; - } - public MaterialAboutSwitchItem setText(CharSequence text) { - this.textRes = 0; - this.text = text; - return this; - } - - public int getTextRes() { - return textRes; - } - - public MaterialAboutSwitchItem setTextRes(int textRes) { - this.text = null; - this.textRes = textRes; - return this; - } - - public CharSequence getSubText() { - return subText; - } - - public MaterialAboutSwitchItem setSubText(CharSequence subText) { - this.subTextRes = 0; - this.subText = subText; - return this; - } - - public int getSubTextRes() { - return subTextRes; - } - - public MaterialAboutSwitchItem setSubTextRes(int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public CharSequence getSubTextChecked() { - return subTextChecked; - } - - public MaterialAboutSwitchItem setSubTextChecked(CharSequence subTextChecked) { - this.subTextCheckedRes = 0; - this.subTextChecked = subTextChecked; - return this; - } - - public int getSubTextCheckedRes() { - return subTextCheckedRes; - } - - public MaterialAboutSwitchItem setSubTextCheckedRes(int subTextCheckedRes) { - this.subTextChecked = null; - this.subTextCheckedRes = subTextCheckedRes; - return this; - } - - public Drawable getIcon() { - return icon; - } - - public MaterialAboutSwitchItem setIcon(Drawable icon) { - this.iconRes = 0; - this.icon = icon; - return this; - } - - public int getIconRes() { - return iconRes; - } - - public MaterialAboutSwitchItem setIconRes(int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public boolean shouldShowIcon() { - return showIcon; - } - - public MaterialAboutSwitchItem setShouldShowIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - @IconGravity - public int getIconGravity() { - return iconGravity; - } - - public MaterialAboutSwitchItem setIconGravity(int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public boolean getChecked() { - return checked; - } - - public MaterialAboutSwitchItem setChecked(boolean checked) { - //Log.d("MaterialItem", "Setting item "+getText()+" to checked "+checked); - this.checked = checked; - return this; - } - - public MaterialAboutItemOnChangeAction getOnChangeAction() { - return onChangeAction; - } - - public MaterialAboutSwitchItem setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - return this; - } - - @Retention(RetentionPolicy.SOURCE) - @IntDef({GRAVITY_TOP, GRAVITY_MIDDLE, GRAVITY_BOTTOM}) - public @interface IconGravity { - } - - public static class Builder { - - MaterialAboutItemOnChangeAction onChangeAction = null; - private CharSequence text = null; - @StringRes - private int textRes = 0; - private CharSequence subText = null; - @StringRes - private int subTextRes = 0; - private CharSequence subTextChecked = null; - @StringRes - private int subTextCheckedRes = 0; - private Drawable icon = null; - @DrawableRes - private int iconRes = 0; - private boolean showIcon = true; - @IconGravity - private int iconGravity = GRAVITY_MIDDLE; - private boolean checked = false; - private int tag = -1; - - public Builder tag(int tag) { - this.tag = tag; - return this; - } - - public Builder text(CharSequence text) { - this.text = text; - this.textRes = 0; - return this; - } - - public Builder text(@StringRes int text) { - this.textRes = text; - this.text = null; - return this; - } - - public Builder subText(CharSequence subText) { - this.subText = subText; - this.subTextRes = 0; - return this; - } - - public Builder subText(@StringRes int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public Builder subTextHtml(String subTextHtml) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - this.subText = Html.fromHtml(subTextHtml, Html.FROM_HTML_MODE_LEGACY); - } else { - //noinspection deprecation - this.subText = Html.fromHtml(subTextHtml); - } - this.subTextRes = 0; - return this; - } - - public Builder subTextChecked(CharSequence subTextChecked) { - this.subTextChecked = subTextChecked; - this.subTextCheckedRes = 0; - return this; - } - - public Builder subTextChecked(@StringRes int subTextCheckedRes) { - this.subTextChecked = null; - this.subTextCheckedRes = subTextCheckedRes; - return this; - } - - public Builder subTextCheckedHtml(String subTextCheckedHtml) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - this.subTextChecked = Html.fromHtml(subTextCheckedHtml, Html.FROM_HTML_MODE_LEGACY); - } else { - //noinspection deprecation - this.subTextChecked = Html.fromHtml(subTextCheckedHtml); - } - this.subTextCheckedRes = 0; - return this; - } - - public Builder icon(Drawable icon) { - this.icon = icon; - this.iconRes = 0; - return this; - } - - public Builder icon(@DrawableRes int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public Builder showIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - public Builder setIconGravity(@IconGravity int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public Builder setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - return this; - } - - public Builder checked(boolean isChecked) { - this.checked = isChecked; - return this; - } - - public MaterialAboutSwitchItem build() { - return new MaterialAboutSwitchItem(this); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutTitleItem.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutTitleItem.java deleted file mode 100644 index a1b1bc72..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutTitleItem.java +++ /dev/null @@ -1,400 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.os.Build; - -import androidx.annotation.ColorInt; -import androidx.annotation.DrawableRes; -import androidx.annotation.StringRes; -import android.util.TypedValue; -import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import static android.view.View.GONE; - -public class MaterialAboutTitleItem extends MaterialAboutItem { - - private CharSequence text = null; - private int textRes = 0; - private CharSequence desc = null; - private int descRes = 0; - private int textColor = -1; - private int descColor = -1; - private Drawable icon = null; - private int iconRes = 0; - private MaterialAboutItemOnClickAction onClickAction = null; - private MaterialAboutItemOnClickAction onLongClickAction = null; - - private MaterialAboutTitleItem(MaterialAboutTitleItem.Builder builder) { - super(); - this.text = builder.text; - this.textRes = builder.textRes; - - this.desc = builder.desc; - this.descRes = builder.descRes; - - this.textColor = builder.textColor; - this.descColor = builder.descColor; - - this.icon = builder.icon; - this.iconRes = builder.iconRes; - - this.onClickAction = builder.onClickAction; - this.onLongClickAction = builder.onLongClickAction; - } - - public MaterialAboutTitleItem(CharSequence text, CharSequence desc, Drawable icon) { - this.text = text; - this.desc = desc; - this.icon = icon; - } - - public MaterialAboutTitleItem(int textRes, int descRes, int iconRes) { - this.textRes = textRes; - this.descRes = descRes; - this.iconRes = iconRes; - } - - public static MaterialAboutItemViewHolder getViewHolder(View view) { - return new MaterialAboutTitleItem.MaterialAboutTitleItemViewHolder(view); - } - - public static void setupItem(MaterialAboutTitleItemViewHolder holder, MaterialAboutTitleItem item, Context context) { - - CharSequence text = item.getText(); - int textRes = item.getTextRes(); - - holder.text.setVisibility(View.VISIBLE); - if (text != null) { - holder.text.setText(text); - } else if (textRes != 0) { - holder.text.setText(textRes); - } else { - holder.text.setVisibility(GONE); - } - - CharSequence desc = item.getDesc(); - int descRes = item.getDescRes(); - - holder.desc.setVisibility(View.VISIBLE); - if (desc != null) { - holder.desc.setText(desc); - } else if (descRes != 0) { - holder.desc.setText(descRes); - } else { - holder.desc.setVisibility(GONE); - } - - if (item.getTextColor() != -1) { - holder.text.setTextColor(item.getTextColor()); - } - if (item.getDescColor() != -1) { - holder.desc.setTextColor(item.getDescColor()); - } - - Drawable drawable = item.getIcon(); - int drawableRes = item.getIconRes(); - if (drawable != null) { - holder.icon.setImageDrawable(drawable); - } else if (drawableRes != 0) { - holder.icon.setImageResource(drawableRes); - } - - int pL = 0, pT = 0, pR = 0, pB = 0; - if (Build.VERSION.SDK_INT < 21) { - pL = holder.view.getPaddingLeft(); - pT = holder.view.getPaddingTop(); - pR = holder.view.getPaddingRight(); - pB = holder.view.getPaddingBottom(); - } - - if (item.getOnClickAction() != null || item.getOnLongClickAction() != null) { - TypedValue outValue = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true); - holder.view.setBackgroundResource(outValue.resourceId); - } else { - holder.view.setBackgroundResource(0); - } - holder.setOnClickAction(item.getOnClickAction()); - holder.setOnLongClickAction(item.getOnLongClickAction()); - - if (Build.VERSION.SDK_INT < 21) { - holder.view.setPadding(pL, pT, pR, pB); - } - } - - @Override - public int getType() { - return ViewTypeManager.ItemType.TITLE_ITEM; - } - - @Override - public String getDetailString() { - return "MaterialAboutTitleItem{" + - "text=" + text + - ", textRes=" + textRes + - ", desc=" + desc + - ", descRes=" + descRes + - ", textColor=" + textColor + - ", descColor=" + descColor + - ", icon=" + icon + - ", iconRes=" + iconRes + - ", onClickAction=" + onClickAction + - ", onLongClickAction=" + onLongClickAction + - '}'; - } - - public MaterialAboutTitleItem(MaterialAboutTitleItem item) { - this.id = item.getId(); - this.text = item.getText(); - this.textRes = item.getTextRes(); - this.desc = item.getDesc(); - this.descRes = item.getDescRes(); - this.textColor = item.getTextColor(); - this.descColor = item.getDescColor(); - this.icon = item.getIcon(); - this.iconRes = item.getIconRes(); - this.onClickAction = item.getOnClickAction(); - this.onLongClickAction = item.getOnLongClickAction(); - } - - @Override - public MaterialAboutTitleItem clone() { - return new MaterialAboutTitleItem(this); - } - - public CharSequence getText() { - return text; - } - - public MaterialAboutTitleItem setText(CharSequence text) { - this.textRes = 0; - this.text = text; - return this; - } - - public int getTextRes() { - return textRes; - } - - public MaterialAboutTitleItem setTextRes(int textRes) { - this.text = null; - this.textRes = textRes; - return this; - } - - public CharSequence getDesc() { - return desc; - } - - public MaterialAboutTitleItem setDesc(CharSequence desc) { - this.descRes = 0; - this.desc = desc; - return this; - } - - public int getDescRes() { - return descRes; - } - - public MaterialAboutTitleItem setDescRes(int descRes) { - this.desc = null; - this.descRes = textRes; - return this; - } - - public int getTextColor() { - return textColor; - } - - public MaterialAboutTitleItem setTextColor(int textColor) { - this.textColor = textColor; - return this; - } - - public int getDescColor() { - return descColor; - } - - public MaterialAboutTitleItem setDescColor(int descColor) { - this.descColor = descColor; - return this; - } - - public Drawable getIcon() { - return icon; - } - - public MaterialAboutTitleItem setIcon(Drawable icon) { - this.iconRes = 0; - this.icon = icon; - return this; - } - - public int getIconRes() { - return iconRes; - } - - public MaterialAboutTitleItem setIconRes(int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public MaterialAboutItemOnClickAction getOnClickAction() { - return onClickAction; - } - - public MaterialAboutTitleItem setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public MaterialAboutItemOnClickAction getOnLongClickAction() { - return onLongClickAction; - } - - public MaterialAboutTitleItem setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - public static class MaterialAboutTitleItemViewHolder extends MaterialAboutItemViewHolder implements View.OnClickListener, View.OnLongClickListener { - public final View view; - public final ImageView icon; - public final TextView text; - public final TextView desc; - private MaterialAboutItemOnClickAction onClickAction; - private MaterialAboutItemOnClickAction onLongClickAction; - - MaterialAboutTitleItemViewHolder(View view) { - super(view); - this.view = view; - icon = (ImageView) view.findViewById(R.id.mal_item_image); - text = (TextView) view.findViewById(R.id.mal_item_text); - desc = (TextView) view.findViewById(R.id.mal_item_desc); - } - - public void setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - if (onClickAction != null) { - view.setOnClickListener(this); - } else { - view.setClickable(false); - } - } - - public void setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - if (onLongClickAction != null) { - view.setOnLongClickListener(this); - } else { - view.setLongClickable(false); - } - } - - @Override - public void onClick(View v) { - if (onClickAction != null) { - onClickAction.onClick(); - } - } - - @Override - public boolean onLongClick(View v) { - if (onLongClickAction != null) { - onLongClickAction.onClick(); - return true; - } - return false; - } - } - - public static class Builder { - - MaterialAboutItemOnClickAction onClickAction = null; - MaterialAboutItemOnClickAction onLongClickAction = null; - private CharSequence text = null; - @StringRes - private int textRes = 0; - private CharSequence desc = null; - @StringRes - private int descRes = 0; - @ColorInt - private int textColor = -1; - @ColorInt - private int descColor = -1; - private Drawable icon = null; - @DrawableRes - private int iconRes = 0; - - public MaterialAboutTitleItem.Builder text(CharSequence text) { - this.text = text; - this.textRes = 0; - return this; - } - - - public MaterialAboutTitleItem.Builder text(@StringRes int text) { - this.textRes = text; - this.text = null; - return this; - } - - public MaterialAboutTitleItem.Builder desc(CharSequence desc) { - this.desc = desc; - this.descRes = 0; - return this; - } - - - public MaterialAboutTitleItem.Builder desc(@StringRes int desc) { - this.descRes = desc; - this.desc = null; - return this; - } - - public MaterialAboutTitleItem.Builder textColor(@ColorInt int textColor) { - this.textColor = textColor; - return this; - } - - public MaterialAboutTitleItem.Builder descColor(@ColorInt int descColor) { - this.descColor = descColor; - return this; - } - - public MaterialAboutTitleItem.Builder icon(Drawable icon) { - this.icon = icon; - this.iconRes = 0; - return this; - } - - - public MaterialAboutTitleItem.Builder icon(@DrawableRes int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public MaterialAboutTitleItem.Builder setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public MaterialAboutTitleItem.Builder setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - - public MaterialAboutTitleItem build() { - return new MaterialAboutTitleItem(this); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutCard.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutCard.java deleted file mode 100644 index ecbffb18..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutCard.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.danielstone.materialaboutlibrary.model; - - -import androidx.annotation.ColorInt; -import androidx.annotation.StringRes; -import androidx.annotation.StyleRes; -import androidx.recyclerview.widget.RecyclerView; - -import com.danielstone.materialaboutlibrary.items.MaterialAboutItem; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.UUID; - -public class MaterialAboutCard { - - private String id = "NO-UUID"; - - private CharSequence title = null; - private int titleRes = 0; - - private int titleColor = 0; - private int cardColor = 0; - - private RecyclerView.Adapter customAdapter = null; - private ArrayList items = new ArrayList<>(); - - - private MaterialAboutCard(Builder builder) { - this.id = UUID.randomUUID().toString(); - this.title = builder.title; - this.titleRes = builder.titleRes; - this.titleColor = builder.titleColor; - this.cardColor = builder.cardColor; - this.items = builder.items; - this.customAdapter = builder.customAdapter; - } - - public MaterialAboutCard(CharSequence title, MaterialAboutItem... materialAboutItems) { - this.title = title; - Collections.addAll(items, materialAboutItems); - } - - public MaterialAboutCard(int titleRes, MaterialAboutItem... materialAboutItems) { - this.titleRes = titleRes; - Collections.addAll(items, materialAboutItems); - } - - public CharSequence getTitle() { - return title; - } - - public int getTitleRes() { - return titleRes; - } - - public int getTitleColor() { - return titleColor; - } - - public int getCardColor() { - return cardColor; - } - - public ArrayList getItems() { - return items; - } - - public static class Builder { - private CharSequence title = null; - @StringRes - private int titleRes = 0; - - @ColorInt - private int titleColor = 0; - - @ColorInt - private int cardColor = 0; - - private ArrayList items = new ArrayList<>(); - private RecyclerView.Adapter customAdapter = null; - - public Builder title(CharSequence title) { - this.title = title; - this.titleRes = 0; - return this; - } - - public Builder title(@StringRes int titleRes) { - this.titleRes = titleRes; - this.title = null; - return this; - } - - public Builder titleColor(@ColorInt int color) { - this.titleColor = color; - return this; - } - - public Builder cardColor(@ColorInt int cardColor) { - this.cardColor = cardColor; - return this; - } - - public Builder addItem(MaterialAboutItem item) { - this.items.add(item); - return this; - } - - public Builder customAdapter(RecyclerView.Adapter customAdapter) { - this.customAdapter = customAdapter; - return this; - } - - public MaterialAboutCard build() { - return new MaterialAboutCard(this); - } - } - - public String getId() { - return id; - } - - public RecyclerView.Adapter getCustomAdapter() { - return customAdapter; - } - - @Override - public String toString() { - String result = "MaterialAboutCard{" + - "id='" + id + '\'' + - ", title=" + title + - ", titleRes=" + titleRes + - ", titleColor=" + titleColor + - ", customAdapter=" + customAdapter + - ", cardColor=" + cardColor + '}'; - return result; - } - - public MaterialAboutCard(MaterialAboutCard card) { - this.id = card.getId(); - this.title = card.getTitle(); - this.titleRes = card.getTitleRes(); - this.titleColor = card.getTitleColor(); - this.cardColor = card.getCardColor(); - this.items = new ArrayList<>(); - this.customAdapter = card.getCustomAdapter(); - for (MaterialAboutItem item : card.items) { - this.items.add(item.clone()); - } - } - public MaterialAboutCard clone() { - return new MaterialAboutCard(this); - } - -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutList.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutList.java deleted file mode 100644 index 910dcc53..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutList.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.danielstone.materialaboutlibrary.model; - - -import java.util.ArrayList; -import java.util.Collections; - -public class MaterialAboutList { - - private ArrayList cards = new ArrayList<>(); - - private MaterialAboutList(Builder builder) { - this.cards = builder.cards; - } - - public MaterialAboutList(MaterialAboutCard... materialAboutCards) { - Collections.addAll(cards, materialAboutCards); - } - - public MaterialAboutList addCard(MaterialAboutCard card) { - cards.add(card); - return this; - } - - public MaterialAboutList clearCards(MaterialAboutCard card) { - cards.clear(); - return this; - } - - public ArrayList getCards() { - return cards; - } - - public static class Builder { - private ArrayList cards = new ArrayList<>(); - - public Builder addCard(MaterialAboutCard card) { - this.cards.add(card); - return this; - } - - public MaterialAboutList build() { - return new MaterialAboutList(this); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/DefaultViewTypeManager.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/DefaultViewTypeManager.java deleted file mode 100644 index 8097c972..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/DefaultViewTypeManager.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.danielstone.materialaboutlibrary.util; - -import android.content.Context; -import android.view.View; - -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem; -import com.danielstone.materialaboutlibrary.items.MaterialAboutActionSwitchItem; -import com.danielstone.materialaboutlibrary.items.MaterialAboutCheckboxItem; -import com.danielstone.materialaboutlibrary.items.MaterialAboutItem; -import com.danielstone.materialaboutlibrary.items.MaterialAboutProfileItem; -import com.danielstone.materialaboutlibrary.items.MaterialAboutSwitchItem; -import com.danielstone.materialaboutlibrary.items.MaterialAboutTitleItem; - -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemLayout.ACTION_LAYOUT; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemLayout.ACTION_SWITCH_LAYOUT; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemLayout.CHECKBOX_LAYOUT; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemLayout.PROFILE_LAYOUT; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemLayout.SWITCH_LAYOUT; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemLayout.TITLE_LAYOUT; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemType.ACTION_ITEM; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemType.ACTION_SWITCH_ITEM; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemType.CHECKBOX_ITEM; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemType.PROFILE_ITEM; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemType.SWITCH_ITEM; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemType.TITLE_ITEM; - -public class DefaultViewTypeManager extends ViewTypeManager { - - public static final class ItemType { - public static final int ACTION_ITEM = ViewTypeManager.ItemType.ACTION_ITEM; - public static final int TITLE_ITEM = ViewTypeManager.ItemType.TITLE_ITEM; - public static final int SWITCH_ITEM = ViewTypeManager.ItemType.SWITCH_ITEM; - public static final int ACTION_SWITCH_ITEM = ViewTypeManager.ItemType.ACTION_SWITCH_ITEM; - public static final int CHECKBOX_ITEM = ViewTypeManager.ItemType.CHECKBOX_ITEM; - public static final int PROFILE_ITEM = ViewTypeManager.ItemType.PROFILE_ITEM; - } - - public static final class ItemLayout { - public static final int ACTION_LAYOUT = ViewTypeManager.ItemLayout.ACTION_LAYOUT; - public static final int TITLE_LAYOUT = ViewTypeManager.ItemLayout.TITLE_LAYOUT; - public static final int SWITCH_LAYOUT = ViewTypeManager.ItemLayout.SWITCH_LAYOUT; - public static final int ACTION_SWITCH_LAYOUT = ViewTypeManager.ItemLayout.ACTION_SWITCH_LAYOUT; - public static final int CHECKBOX_LAYOUT = ViewTypeManager.ItemLayout.CHECKBOX_LAYOUT; - public static final int PROFILE_LAYOUT = ViewTypeManager.ItemLayout.PROFILE_LAYOUT; - } - - public int getLayout(int itemType) { - switch (itemType) { - case ACTION_ITEM: - return ACTION_LAYOUT; - case TITLE_ITEM: - return TITLE_LAYOUT; - case SWITCH_ITEM: - return SWITCH_LAYOUT; - case ACTION_SWITCH_ITEM: - return ACTION_SWITCH_LAYOUT; - case CHECKBOX_ITEM: - return CHECKBOX_LAYOUT; - case PROFILE_ITEM: - return PROFILE_LAYOUT; - default: - return -1; - } - } - - public MaterialAboutItemViewHolder getViewHolder(int itemType, View view) { - switch (itemType) { - case ACTION_ITEM: - return MaterialAboutActionItem.getViewHolder(view); - case TITLE_ITEM: - return MaterialAboutTitleItem.getViewHolder(view); - case SWITCH_ITEM: - return MaterialAboutSwitchItem.getViewHolder(view); - case ACTION_SWITCH_ITEM: - return MaterialAboutActionSwitchItem.getViewHolder(view); - case CHECKBOX_ITEM: - return MaterialAboutCheckboxItem.getViewHolder(view); - case PROFILE_ITEM: - return MaterialAboutProfileItem.getViewHolder(view); - default: - return null; - } - } - - public void setupItem(int itemType, MaterialAboutItemViewHolder holder, MaterialAboutItem item, Context context) { - switch (itemType) { - case ACTION_ITEM: - MaterialAboutActionItem.setupItem((MaterialAboutActionItem.MaterialAboutActionItemViewHolder) holder, (MaterialAboutActionItem) item, context); - break; - case TITLE_ITEM: - MaterialAboutTitleItem.setupItem((MaterialAboutTitleItem.MaterialAboutTitleItemViewHolder) holder, (MaterialAboutTitleItem) item, context); - break; - case SWITCH_ITEM: - MaterialAboutSwitchItem.setupItem((MaterialAboutSwitchItem.MaterialAboutSwitchItemViewHolder) holder, (MaterialAboutSwitchItem) item, context); - break; - case ACTION_SWITCH_ITEM: - MaterialAboutActionSwitchItem.setupItem((MaterialAboutActionSwitchItem.MaterialAboutActionSwitchItemViewHolder) holder, (MaterialAboutActionSwitchItem) item, context); - break; - case CHECKBOX_ITEM: - MaterialAboutCheckboxItem.setupItem((MaterialAboutCheckboxItem.MaterialAboutCheckboxItemViewHolder) holder, (MaterialAboutCheckboxItem) item, context); - break; - case PROFILE_ITEM: - MaterialAboutProfileItem.setupItem((MaterialAboutProfileItem.MaterialAboutProfileItemViewHolder) holder, (MaterialAboutProfileItem) item, context); - break; - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/OpenSourceLicense.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/OpenSourceLicense.java deleted file mode 100644 index c916b2b6..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/OpenSourceLicense.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.danielstone.materialaboutlibrary.util; - -import com.danielstone.materialaboutlibrary.R; - -public enum OpenSourceLicense { - APACHE_2, MIT, GNU_GPL_3, BSD; - - public int getResourceId() { - switch (this) { - case APACHE_2: - return R.string.license_apache2; - case MIT: - return R.string.license_mit; - case GNU_GPL_3: - return R.string.license_gpl; - case BSD: - return R.string.license_bsd; - default: - return -1; - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/ViewTypeManager.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/ViewTypeManager.java deleted file mode 100644 index d496dadd..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/ViewTypeManager.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.danielstone.materialaboutlibrary.util; - -import android.content.Context; -import android.view.View; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.items.MaterialAboutItem; - -public abstract class ViewTypeManager { - - public static final class ItemType { - public static final int ACTION_ITEM = 0; - public static final int TITLE_ITEM = 1; - public static final int SWITCH_ITEM = 2; - public static final int ACTION_SWITCH_ITEM = 3; - public static final int CHECKBOX_ITEM = 4; - public static final int PROFILE_ITEM = 5; - } - - public static final class ItemLayout { - public static final int ACTION_LAYOUT = R.layout.mal_material_about_action_item; - public static final int TITLE_LAYOUT = R.layout.mal_material_about_title_item; - public static final int SWITCH_LAYOUT = R.layout.mal_material_about_switch_item; - public static final int ACTION_SWITCH_LAYOUT = R.layout.mal_material_about_action_switch_item; - public static final int CHECKBOX_LAYOUT = R.layout.mal_material_about_checkbox_item; - public static final int PROFILE_LAYOUT = R.layout.mal_material_about_profile_item; - } - - public abstract int getLayout(int itemType); - - public abstract MaterialAboutItemViewHolder getViewHolder(int itemType, View view); - - public abstract void setupItem(int itemType, MaterialAboutItemViewHolder holder, MaterialAboutItem item, Context context); -} diff --git a/material-about-library/src/main/res/layout/mal_material_about_action_item.xml b/material-about-library/src/main/res/layout/mal_material_about_action_item.xml deleted file mode 100644 index 5edc81d4..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_action_item.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/layout/mal_material_about_action_switch_item.xml b/material-about-library/src/main/res/layout/mal_material_about_action_switch_item.xml deleted file mode 100644 index 9e1dd978..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_action_switch_item.xml +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/layout/mal_material_about_activity.xml b/material-about-library/src/main/res/layout/mal_material_about_activity.xml deleted file mode 100644 index 42f77361..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_activity.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - diff --git a/material-about-library/src/main/res/layout/mal_material_about_checkbox_item.xml b/material-about-library/src/main/res/layout/mal_material_about_checkbox_item.xml deleted file mode 100644 index 659bbd1f..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_checkbox_item.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/layout/mal_material_about_fragment.xml b/material-about-library/src/main/res/layout/mal_material_about_fragment.xml deleted file mode 100644 index f8bdb8e0..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_fragment.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/layout/mal_material_about_list_card.xml b/material-about-library/src/main/res/layout/mal_material_about_list_card.xml deleted file mode 100644 index 0d1f73e8..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_list_card.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/layout/mal_material_about_profile_item.xml b/material-about-library/src/main/res/layout/mal_material_about_profile_item.xml deleted file mode 100644 index a90ccba1..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_profile_item.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/layout/mal_material_about_switch_item.xml b/material-about-library/src/main/res/layout/mal_material_about_switch_item.xml deleted file mode 100644 index b888bc0f..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_switch_item.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/layout/mal_material_about_title_item.xml b/material-about-library/src/main/res/layout/mal_material_about_title_item.xml deleted file mode 100644 index e77e04c8..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_title_item.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/values/attrs.xml b/material-about-library/src/main/res/values/attrs.xml deleted file mode 100644 index 9d555688..00000000 --- a/material-about-library/src/main/res/values/attrs.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/values/colors.xml b/material-about-library/src/main/res/values/colors.xml deleted file mode 100644 index 057f6cb3..00000000 --- a/material-about-library/src/main/res/values/colors.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - #de000000 - #8a000000 - - #ff9b9b9b - \ No newline at end of file diff --git a/material-about-library/src/main/res/values/dimens.xml b/material-about-library/src/main/res/values/dimens.xml deleted file mode 100644 index 06796bac..00000000 --- a/material-about-library/src/main/res/values/dimens.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - 16dp - 8dp - - 24dp - 32dp - 40dp - - 4dp - 4dp - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/values/strings.xml b/material-about-library/src/main/res/values/strings.xml deleted file mode 100644 index cbe49a18..00000000 --- a/material-about-library/src/main/res/values/strings.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - About - - Close - Send email - - No apps to handle action - - - "\nCopyright %1$s %2$s\n" - - "\nLicensed under the Apache License, Version 2.0 (the \"License\");" - "you may not use this file except in compliance with the License." - "You may obtain a copy of the License at\n" - - "\nhttp://www.apache.org/licenses/LICENSE-2.0\n" - - "\nUnless required by applicable law or agreed to in writing, software" - "distributed under the License is distributed on an \"AS IS\" BASIS," - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." - "See the License for the specific language governing permissions and" - "limitations under the License." - - - - "\nMIT License\n" - - "\nCopyright © %1$s %2$s\n" - - "\nPermission is hereby granted, free of charge, to any person obtaining a copy" - "of this software and associated documentation files (the "Software"), to deal" - "in the Software without restriction, including without limitation the rights" - "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell" - "copies of the Software, and to permit persons to whom the Software is" - "furnished to do so, subject to the following conditions:\n" - - "\nThe above copyright notice and this permission notice shall be included in all" - "copies or substantial portions of the Software.\n" - - "\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR" - "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY," - "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE" - "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER" - "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM," - "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE" - "SOFTWARE." - - - - "\nCopyright © %1$s %2$s\n" - - "\nThis program is free software: you can redistribute it and/or modify" - "it under the terms of the GNU General Public License as published by" - "the Free Software Foundation, either version 3 of the License, or" - "(at your option) any later version.\n" - - "\nThis program is distributed in the hope that it will be useful," - "but WITHOUT ANY WARRANTY; without even the implied warranty of" - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" - "GNU General Public License for more details.\n" - - "\nYou should have received a copy of the GNU General Public License" - "along with this program. If not, see http://www.gnu.org/licenses.\n" - - - - "\nCopyright © %1$s %2$s\n" - - "\nRedistribution and use in source and binary forms, with or without" - "modification, are permitted provided that the following conditions are met:\n" - - "\n1. Redistributions of source code must retain the above copyright notice, this" - " list of conditions and the following disclaimer.\n" - "2. Redistributions in binary form must reproduce the above copyright notice," - " this list of conditions and the following disclaimer in the documentation" - " and/or other materials provided with the distribution.\n" - - "\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND" - "ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED" - "WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE" - "DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR" - "ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES" - "(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;" - "LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND" - "ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT" - "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS" - "SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" - - "\nThe views and conclusions contained in the software and documentation are those" - "of the authors and should not be interpreted as representing official policies," - "either expressed or implied, of the FreeBSD Project.\n" - - diff --git a/material-about-library/src/main/res/values/styles.xml b/material-about-library/src/main/res/values/styles.xml deleted file mode 100644 index d0c6188b..00000000 --- a/material-about-library/src/main/res/values/styles.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index b43e4d66..02529180 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,9 +1,2 @@ -include ':wear' -include ':wear' -include ':codegen' -include ':annotation' rootProject.name='Szkolny.eu' -include ':app', ':agendacalendarview', ':mhttp', ':material-about-library', ':cafebar', ':szkolny-font', ':nachos' -/* -include ':Navigation' -project(':Navigation').projectDir = new File(settingsDir, '../Navigation/navlib')*/ +include ':app' diff --git a/szkolny-font/build.gradle b/szkolny-font/build.gradle deleted file mode 100644 index 70d20b0d..00000000 --- a/szkolny-font/build.gradle +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2019 Mike Penz - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -apply plugin: 'com.android.library' - -apply plugin: 'kotlin-android' - -android { - compileSdkVersion setup.compileSdk - - defaultConfig { - minSdkVersion setup.minSdk - targetSdkVersion setup.targetSdk - consumerProguardFiles 'consumer-proguard-rules.pro' - versionCode 11 - versionName "1.1" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - debugMinify { - debuggable = true - minifyEnabled = true - proguardFiles 'proguard-android.txt' - } - } -} -if (project.hasProperty('pushall') || project.hasProperty('SzkolnyFontonly')) { - apply from: '../gradle-mvn-push.gradle' -} - -dependencies { - implementation "com.mikepenz:iconics-core:${versions.iconics}" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}" -} diff --git a/szkolny-font/consumer-proguard-rules.pro b/szkolny-font/consumer-proguard-rules.pro deleted file mode 100644 index 61d1083d..00000000 --- a/szkolny-font/consumer-proguard-rules.pro +++ /dev/null @@ -1 +0,0 @@ --keep class com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont { *; } diff --git a/szkolny-font/gradle.properties b/szkolny-font/gradle.properties deleted file mode 100644 index 82ee377a..00000000 --- a/szkolny-font/gradle.properties +++ /dev/null @@ -1,40 +0,0 @@ -# -# Copyright 2014 Mike Penz -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# Project-wide Gradle settings. - -# IDE (e.g. Android Studio) users: -# Settings specified in this file will override any Gradle settings -# configured through the IDE. - -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html - -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -# Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true -VERSION_NAME=1.0 -VERSION_CODE=1 - -POM_NAME=Android-Iconics Szkolny.eu Icon Font Typeface Library -POM_ARTIFACT_ID=szkolny-font-typeface -POM_PACKAGING=aar diff --git a/szkolny-font/src/main/AndroidManifest.xml b/szkolny-font/src/main/AndroidManifest.xml deleted file mode 100644 index e4bf2179..00000000 --- a/szkolny-font/src/main/AndroidManifest.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - diff --git a/szkolny-font/src/main/java/com/mikepenz/iconics/typeface/library/szkolny/font/SzkolnyFont.kt b/szkolny-font/src/main/java/com/mikepenz/iconics/typeface/library/szkolny/font/SzkolnyFont.kt deleted file mode 100644 index 5e23dbd1..00000000 --- a/szkolny-font/src/main/java/com/mikepenz/iconics/typeface/library/szkolny/font/SzkolnyFont.kt +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2019 Mike Penz - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mikepenz.iconics.typeface.library.szkolny.font - -import com.mikepenz.iconics.typeface.IIcon -import com.mikepenz.iconics.typeface.ITypeface -import com.mikepenz.iconics.typeface.library.szkolny.R -import java.util.* - -@Suppress("EnumEntryName") -object SzkolnyFont : ITypeface { - - override val fontRes: Int - get() = R.font.szkolny_font_font_v1_1 - - override val characters: Map by lazy { - Icon.values().associate { it.name to it.character } - } - - override val mappingPrefix: String - get() = "szf" - - override val fontName: String - get() = "Szkolny Font" - - override val version: String - get() = "1.1" - - override val iconCount: Int - get() = characters.size - - override val icons: List - get() = characters.keys.toCollection(LinkedList()) - - override val author: String - get() = "Kuba" - - override val url: String - get() = "" - - override val description: String - get() = "" - - override val license: String - get() = "" - - override val licenseUrl: String - get() = "" - - override fun getIcon(key: String): IIcon = Icon.valueOf(key) - - enum class Icon constructor(override val character: Char) : IIcon { - szf_alarm_bell_outline('\ue800'), - szf_calendar_plus_outline('\ue801'), - szf_calendar_today_outline('\ue802'), - szf_clipboard_list_outline('\ue803'), - szf_delete_empty_outline('\ue804'), - szf_discord_outline('\ue805'), - szf_file_code_outline('\ue806'), - szf_file_excel_outline('\ue807'), - szf_file_image_outline('\ue808'), - szf_file_music_outline('\ue809'), - szf_file_pdf_outline('\ue80a'), - szf_file_percent_outline('\ue80b'), - szf_file_powerpoint_outline('\ue80c'), - szf_file_video_outline('\ue80d'), - szf_file_word_outline('\ue80e'), - szf_message_processing_outline('\ue80f'), - szf_notebook_outline('\ue810'), - szf_zip_box_outline('\ue811'); - - override val typeface: ITypeface by lazy { SzkolnyFont } - } -} \ No newline at end of file diff --git a/szkolny-font/src/main/res/font/szkolny_font_font_v1_1.ttf b/szkolny-font/src/main/res/font/szkolny_font_font_v1_1.ttf deleted file mode 100644 index 33ad627f..00000000 Binary files a/szkolny-font/src/main/res/font/szkolny_font_font_v1_1.ttf and /dev/null differ diff --git a/szkolny-font/src/main/res/values/font_addon.xml b/szkolny-font/src/main/res/values/font_addon.xml deleted file mode 100644 index 3ea04e70..00000000 --- a/szkolny-font/src/main/res/values/font_addon.xml +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/wear/.gitignore b/wear/.gitignore deleted file mode 100644 index 796b96d1..00000000 --- a/wear/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/wear/build.gradle b/wear/build.gradle deleted file mode 100644 index 5b531ae4..00000000 --- a/wear/build.gradle +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) Kacper Ziubryniewicz 2020-9-17 - */ - -plugins { - id 'com.android.application' - id 'kotlin-android' -} - -android { - compileSdkVersion 29 - buildToolsVersion "29.0.3" - - defaultConfig { - applicationId "pl.szczodrzynski.edziennik" - minSdkVersion 23 - targetSdkVersion 29 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - kotlinOptions { - jvmTarget = '1.8' - } -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}" - implementation 'androidx.core:core-ktx:1.3.1' - implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'com.google.android.material:material:1.2.1' - testImplementation 'junit:junit:4.13' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' - - implementation 'androidx.wear:wear:1.0.0' - implementation 'com.google.android.support:wearable:2.7.0' - compileOnly 'com.google.android.wearable:wearable:2.7.0' - - implementation "com.google.android.gms:play-services-wearable:${versions.play_services}" -} diff --git a/wear/proguard-rules.pro b/wear/proguard-rules.pro deleted file mode 100644 index f1b42451..00000000 --- a/wear/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile diff --git a/wear/src/androidTest/java/pl/szczodrzynski/edziennik/ExampleInstrumentedTest.kt b/wear/src/androidTest/java/pl/szczodrzynski/edziennik/ExampleInstrumentedTest.kt deleted file mode 100644 index 84289796..00000000 --- a/wear/src/androidTest/java/pl/szczodrzynski/edziennik/ExampleInstrumentedTest.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) Kacper Ziubryniewicz 2020-9-17 - */ - -package pl.szczodrzynski.edziennik - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.platform.app.InstrumentationRegistry -import org.junit.Assert.assertEquals -import org.junit.Test -import org.junit.runner.RunWith - -/** - * Instrumented test, which will execute on an Android device. - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("pl.szczodrzynski.edziennik", appContext.packageName) - } -} diff --git a/wear/src/main/AndroidManifest.xml b/wear/src/main/AndroidManifest.xml deleted file mode 100644 index 803bc28d..00000000 --- a/wear/src/main/AndroidManifest.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/wear/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt b/wear/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt deleted file mode 100644 index ed694372..00000000 --- a/wear/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) Kacper Ziubryniewicz 2020-9-17 - */ - -package pl.szczodrzynski.edziennik - -import android.os.Bundle -import android.support.wearable.activity.WearableActivity -import com.google.android.gms.wearable.* - -class MainActivity : WearableActivity(), DataClient.OnDataChangedListener { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - - // Enables Always-on - setAmbientEnabled() - } - - override fun onDataChanged(dataEvents: DataEventBuffer) { - dataEvents.forEach { event -> - if (event.type == DataEvent.TYPE_CHANGED) { - event.dataItem.also { item -> - if (item?.uri?.path?.compareTo("/test") == 0) { - DataMapItem.fromDataItem(item).dataMap.apply { - getInt("test") - } - } - } - } else if (event.type == DataEvent.TYPE_DELETED) { - // DataItem deleted - } - - } - } - - override fun onResume() { - super.onResume() - Wearable.getDataClient(this).addListener(this) - } - - override fun onPause() { - super.onPause() - Wearable.getDataClient(this).removeListener(this) - } -} diff --git a/wear/src/main/res/drawable-v24/ic_launcher_foreground.xml b/wear/src/main/res/drawable-v24/ic_launcher_foreground.xml deleted file mode 100644 index d36dec1a..00000000 --- a/wear/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - diff --git a/wear/src/main/res/drawable/ic_launcher_background.xml b/wear/src/main/res/drawable/ic_launcher_background.xml deleted file mode 100644 index f14b2240..00000000 --- a/wear/src/main/res/drawable/ic_launcher_background.xml +++ /dev/null @@ -1,174 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/wear/src/main/res/layout/activity_main.xml b/wear/src/main/res/layout/activity_main.xml deleted file mode 100644 index 8d270149..00000000 --- a/wear/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - diff --git a/wear/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/wear/src/main/res/mipmap-anydpi-v26/ic_launcher.xml deleted file mode 100644 index 16e1857e..00000000 --- a/wear/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - diff --git a/wear/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/wear/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml deleted file mode 100644 index 16e1857e..00000000 --- a/wear/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - diff --git a/wear/src/main/res/mipmap-hdpi/ic_launcher.png b/wear/src/main/res/mipmap-hdpi/ic_launcher.png deleted file mode 100644 index a571e600..00000000 Binary files a/wear/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ diff --git a/wear/src/main/res/mipmap-hdpi/ic_launcher_round.png b/wear/src/main/res/mipmap-hdpi/ic_launcher_round.png deleted file mode 100644 index 61da551c..00000000 Binary files a/wear/src/main/res/mipmap-hdpi/ic_launcher_round.png and /dev/null differ diff --git a/wear/src/main/res/mipmap-mdpi/ic_launcher.png b/wear/src/main/res/mipmap-mdpi/ic_launcher.png deleted file mode 100644 index c41dd285..00000000 Binary files a/wear/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ diff --git a/wear/src/main/res/mipmap-mdpi/ic_launcher_round.png b/wear/src/main/res/mipmap-mdpi/ic_launcher_round.png deleted file mode 100644 index db5080a7..00000000 Binary files a/wear/src/main/res/mipmap-mdpi/ic_launcher_round.png and /dev/null differ diff --git a/wear/src/main/res/mipmap-xhdpi/ic_launcher.png b/wear/src/main/res/mipmap-xhdpi/ic_launcher.png deleted file mode 100644 index 6dba46da..00000000 Binary files a/wear/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ diff --git a/wear/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/wear/src/main/res/mipmap-xhdpi/ic_launcher_round.png deleted file mode 100644 index da31a871..00000000 Binary files a/wear/src/main/res/mipmap-xhdpi/ic_launcher_round.png and /dev/null differ diff --git a/wear/src/main/res/mipmap-xxhdpi/ic_launcher.png b/wear/src/main/res/mipmap-xxhdpi/ic_launcher.png deleted file mode 100644 index 15ac6817..00000000 Binary files a/wear/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/wear/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/wear/src/main/res/mipmap-xxhdpi/ic_launcher_round.png deleted file mode 100644 index b216f2d3..00000000 Binary files a/wear/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/wear/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/wear/src/main/res/mipmap-xxxhdpi/ic_launcher.png deleted file mode 100644 index f25a4197..00000000 Binary files a/wear/src/main/res/mipmap-xxxhdpi/ic_launcher.png and /dev/null differ diff --git a/wear/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/wear/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png deleted file mode 100644 index e96783cc..00000000 Binary files a/wear/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/wear/src/main/res/values-night/themes.xml b/wear/src/main/res/values-night/themes.xml deleted file mode 100644 index ad19c38e..00000000 --- a/wear/src/main/res/values-night/themes.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - diff --git a/wear/src/main/res/values-round/strings.xml b/wear/src/main/res/values-round/strings.xml deleted file mode 100644 index 62eacd26..00000000 --- a/wear/src/main/res/values-round/strings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - Hello Round World! - diff --git a/wear/src/main/res/values/colors.xml b/wear/src/main/res/values/colors.xml deleted file mode 100644 index a7c719f0..00000000 --- a/wear/src/main/res/values/colors.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - #FFBB86FC - #FF6200EE - #FF3700B3 - #FF03DAC5 - #FF018786 - #FF000000 - #FFFFFFFF - diff --git a/wear/src/main/res/values/dimens.xml b/wear/src/main/res/values/dimens.xml deleted file mode 100644 index 2e76f3e3..00000000 --- a/wear/src/main/res/values/dimens.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - 0dp - - - 5dp - diff --git a/wear/src/main/res/values/strings.xml b/wear/src/main/res/values/strings.xml deleted file mode 100644 index bbaabade..00000000 --- a/wear/src/main/res/values/strings.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - Szkolny.eu - - Hello Square World! - diff --git a/wear/src/main/res/values/themes.xml b/wear/src/main/res/values/themes.xml deleted file mode 100644 index 58cc0c22..00000000 --- a/wear/src/main/res/values/themes.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - diff --git a/wear/src/test/java/pl/szczodrzynski/edziennik/ExampleUnitTest.kt b/wear/src/test/java/pl/szczodrzynski/edziennik/ExampleUnitTest.kt deleted file mode 100644 index affae81c..00000000 --- a/wear/src/test/java/pl/szczodrzynski/edziennik/ExampleUnitTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) Kacper Ziubryniewicz 2020-9-17 - */ - -package pl.szczodrzynski.edziennik - -import org.junit.Assert.assertEquals -import org.junit.Test - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -}