Skip to content

Commit

Permalink
Merge pull request #937 from StepicOrg/feature/APPS_3544_profile_cert…
Browse files Browse the repository at this point in the history
…ificates_redesign

APPS-3544: Profile certificates redesign
  • Loading branch information
rostikjoystick authored Jan 25, 2022
2 parents 359061e + a9783e7 commit 98ebcbf
Show file tree
Hide file tree
Showing 29 changed files with 385 additions and 173 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/org/stepic/droid/core/ScreenManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.stepic.droid.model.CertificateViewItem;
import org.stepic.droid.model.CertificateListItem;
import org.stepic.droid.social.SocialMedia;
import org.stepik.android.domain.auth.model.SocialAuthType;
import org.stepik.android.domain.course.analytic.CourseViewSource;
Expand Down Expand Up @@ -91,7 +91,7 @@ public interface ScreenManager {

void openInWeb(Activity context, String path);

void addCertificateToLinkedIn(CertificateViewItem certificateViewItem);
void addCertificateToLinkedIn(CertificateListItem.Data certificateListItem);

void showCertificates(Context context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.stepic.droid.configuration.EndpointResolver;
import org.stepic.droid.configuration.Config;
import org.stepic.droid.di.AppSingleton;
import org.stepic.droid.model.CertificateViewItem;
import org.stepic.droid.model.CertificateListItem;
import org.stepic.droid.preferences.SharedPreferenceHelper;
import org.stepic.droid.preferences.UserPreferences;
import org.stepic.droid.social.SocialMedia;
Expand Down Expand Up @@ -531,17 +531,17 @@ public void openInWeb(Activity context, String path) {
}

@Override
public void addCertificateToLinkedIn(CertificateViewItem certificateViewItem) {
public void addCertificateToLinkedIn(CertificateListItem.Data certificateListItem) {
// TODO: 19/10/2017 linkedin exporting is not working due to changing API params is not filled

StringBuilder sb = new StringBuilder();
sb.append(AppConstants.LINKEDIN_ADD_URL);
sb.append("_ed=");//linkedin id parameter
sb.append(AppConstants.LINKEDIN_ED_ID);
sb.append("&pfCertificationName="); // linkedin cert name
sb.append(URLEncoder.encode(certificateViewItem.getTitle()));
sb.append(URLEncoder.encode(certificateListItem.getTitle()));
sb.append("&pfCertificationUrl=");//linkedin certificate url
sb.append(certificateViewItem.getCertificate().getUrl());
sb.append(certificateListItem.getCertificate().getUrl());


final Intent intent = new Intent(Intent.ACTION_VIEW);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/stepic/droid/core/ShareHelper.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.stepic.droid.core

import android.content.Intent
import org.stepic.droid.model.CertificateViewItem
import org.stepic.droid.model.CertificateListItem
import org.stepik.android.model.*
import org.stepik.android.model.Unit
import org.stepik.android.model.user.User

interface ShareHelper {
fun getIntentForCourseSharing(course: Course): Intent

fun getIntentForShareCertificate(certificateViewItem: CertificateViewItem): Intent
fun getIntentForShareCertificate(certificateListItem: CertificateListItem.Data): Intent

fun getIntentForStepSharing(step: Step, lesson: Lesson, unit: Unit?): Intent

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/org/stepic/droid/core/ShareHelperImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.net.Uri
import org.stepic.droid.R
import org.stepic.droid.configuration.EndpointResolver
import org.stepic.droid.di.AppSingleton
import org.stepic.droid.model.CertificateViewItem
import org.stepic.droid.model.CertificateListItem
import org.stepic.droid.util.StringUtil
import org.stepic.droid.util.resolvers.text.TextResolver
import org.stepik.android.model.*
Expand Down Expand Up @@ -46,8 +46,8 @@ constructor(
return getShareIntentBase(textForSharing)
}

override fun getIntentForShareCertificate(certificateViewItem: CertificateViewItem): Intent =
getShareIntentBase(certificateViewItem.certificate.url ?: " ")
override fun getIntentForShareCertificate(certificateListItem: CertificateListItem.Data): Intent =
getShareIntentBase(certificateListItem.certificate.url ?: " ")

override fun getIntentForStepSharing(step: Step, lesson: Lesson, unit: Unit?): Intent {
val textForSharing = Uri.parse(StringUtil.getUriForStep(endpointResolver.getBaseUrl(), lesson, unit, step)).toString()
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/org/stepic/droid/model/CertificateListItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.stepic.droid.model

import android.os.Parcelable
import kotlinx.android.parcel.Parcelize
import org.stepik.android.model.Certificate

sealed class CertificateListItem : Parcelable {
@Parcelize
data class Data(
val certificate: Certificate,
val title: String?,
val coverFullPath: String?
) : CertificateListItem()

@Parcelize
object Placeholder : CertificateListItem()
}
35 changes: 0 additions & 35 deletions app/src/main/java/org/stepic/droid/model/CertificateViewItem.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package org.stepic.droid.storage.migration
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import org.stepic.droid.storage.structure.DbStructureCourse
import org.stepik.android.cache.certificates.structure.DbStructureCertificate

object MigrationFrom78To79 : Migration(78, 79) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE ${DbStructureCertificate.TABLE_NAME} ADD COLUMN ${DbStructureCertificate.Columns.IS_WITH_SCORE} INTEGER DEFAULT 1")
db.execSQL("ALTER TABLE ${DbStructureCourse.TABLE_NAME} ADD COLUMN ${DbStructureCourse.Columns.ANNOUNCEMENTS} TEXT")
db.execSQL("CREATE TABLE IF NOT EXISTS `Announcement` (`id` INTEGER NOT NULL, `course` INTEGER NOT NULL, `user` INTEGER, `subject` TEXT NOT NULL, `text` TEXT NOT NULL, `createDate` INTEGER, `nextDate` INTEGER, `sentDate` INTEGER, `status` TEXT NOT NULL, `isRestrictedByScore` INTEGER NOT NULL, `scorePercentMin` INTEGER NOT NULL, `scorePercentMax` INTEGER NOT NULL, `emailTemplate` TEXT, `isScheduled` INTEGER NOT NULL, `startDate` INTEGER, `mailPeriodDays` INTEGER NOT NULL, `mailQuantity` INTEGER NOT NULL, `isInfinite` INTEGER NOT NULL, `onEnroll` INTEGER NOT NULL, `publishCount` INTEGER, `queueCount` INTEGER, `sentCount` INTEGER, `openCount` INTEGER, `clickCount` INTEGER, `estimatedStartDate` INTEGER, `estimatedFinishDate` INTEGER, `noticeDates` TEXT NOT NULL, PRIMARY KEY(`id`))")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.stepic.droid.base.App;
import org.stepic.droid.core.ScreenManager;
import org.stepic.droid.core.ShareHelper;
import org.stepic.droid.model.CertificateViewItem;
import org.stepic.droid.model.CertificateListItem;
import org.stepic.droid.util.ContextExtensionsKt;
import org.stepic.droid.util.DisplayUtils;

Expand All @@ -25,7 +25,7 @@
public class CertificateShareDialog extends BottomSheetDialog {

@NotNull
private final CertificateViewItem certificateViewItem;
private final CertificateListItem.Data certificateListItem;

@Inject
ScreenManager screenManager;
Expand All @@ -36,9 +36,9 @@ public class CertificateShareDialog extends BottomSheetDialog {
@Inject
Analytic analytic;

public CertificateShareDialog(@NonNull Context context, @NotNull CertificateViewItem certificateViewItem) {
public CertificateShareDialog(@NonNull Context context, @NotNull CertificateListItem.Data certificateListItem) {
super(context);
this.certificateViewItem = certificateViewItem;
this.certificateListItem = certificateListItem;
App.Companion.component().inject(this);
}

Expand All @@ -61,7 +61,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onClick(View view) {
dismiss();
screenManager.addCertificateToLinkedIn(certificateViewItem);
screenManager.addCertificateToLinkedIn(certificateListItem);
}
});

Expand All @@ -73,7 +73,7 @@ public void onClick(View view) {
ContextExtensionsKt.copyTextToClipboard(
getContext(),
App.Companion.getAppContext().getString(R.string.copy_link_title),
certificateViewItem.getCertificate().getUrl(),
certificateListItem.getCertificate().getUrl(),
getContext().getResources().getString(R.string.link_copied_title)
);
}
Expand All @@ -84,7 +84,7 @@ public void onClick(View view) {
public void onClick(View view) {
dismiss();
analytic.reportEvent(Analytic.Certificate.SHARE_LINK_CERTIFICATE);
Intent intent = shareHelper.getIntentForShareCertificate(certificateViewItem);
Intent intent = shareHelper.getIntentForShareCertificate(certificateListItem);
getContext().startActivity(intent);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import androidx.fragment.app.DialogFragment;

import org.jetbrains.annotations.NotNull;
import org.stepic.droid.model.CertificateViewItem;
import org.stepic.droid.model.CertificateListItem;

public class CertificateShareDialogFragment extends DialogFragment {

public static final String TAG = "certificate_share_dialog";
private static final String CERTIFICATE_VIEW_ITEM_KEY = "certificateViewItemKey";

public static DialogFragment newInstance(@NotNull CertificateViewItem viewItem) {
public static DialogFragment newInstance(@NotNull CertificateListItem.Data viewItem) {
Bundle args = new Bundle();
args.putParcelable(CERTIFICATE_VIEW_ITEM_KEY, viewItem);
DialogFragment fragment = new CertificateShareDialogFragment();
Expand All @@ -25,7 +25,7 @@ public static DialogFragment newInstance(@NotNull CertificateViewItem viewItem)
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
CertificateViewItem viewItem = getArguments().getParcelable(CERTIFICATE_VIEW_ITEM_KEY);
CertificateListItem.Data viewItem = getArguments().getParcelable(CERTIFICATE_VIEW_ITEM_KEY);
return new CertificateShareDialog(getContext(), viewItem);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.stepic.droid.util.getDate
import org.stepic.droid.util.getInt
import org.stepic.droid.util.getLong
import org.stepic.droid.util.getString
import org.stepic.droid.util.getBoolean
import org.stepik.android.cache.certificates.structure.DbStructureCertificate
import org.stepik.android.model.Certificate
import javax.inject.Inject
Expand Down Expand Up @@ -43,7 +44,8 @@ constructor(
previewUrl = cursor.getString(DbStructureCertificate.Columns.PREVIEW_URL),
savedFullName = cursor.getString(DbStructureCertificate.Columns.SAVED_FULLNAME),
editsCount = cursor.getInt(DbStructureCertificate.Columns.EDITS_COUNT),
allowedEditsCount = cursor.getInt(DbStructureCertificate.Columns.ALLOWED_EDITS_COUNT)
allowedEditsCount = cursor.getInt(DbStructureCertificate.Columns.ALLOWED_EDITS_COUNT),
isWithScore = cursor.getBoolean(DbStructureCertificate.Columns.IS_WITH_SCORE)
)

override fun getContentValues(persistentObject: Certificate): ContentValues =
Expand All @@ -63,5 +65,6 @@ constructor(
put(DbStructureCertificate.Columns.SAVED_FULLNAME, persistentObject.savedFullName)
put(DbStructureCertificate.Columns.EDITS_COUNT, persistentObject.editsCount)
put(DbStructureCertificate.Columns.ALLOWED_EDITS_COUNT, persistentObject.allowedEditsCount)
put(DbStructureCertificate.Columns.IS_WITH_SCORE, persistentObject.isWithScore)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ object DbStructureCertificate {
const val SAVED_FULLNAME = "saved_fullname"
const val EDITS_COUNT = "edits_count"
const val ALLOWED_EDITS_COUNT = "allowed_edits_count"
const val IS_WITH_SCORE = "is_with_score"
}

fun createTable(db: SupportSQLiteDatabase) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.stepik.android.domain.certificate.interactor

import io.reactivex.Single
import org.stepic.droid.model.CertificateViewItem
import org.stepic.droid.model.CertificateListItem
import ru.nobird.android.core.model.PagedList
import org.stepik.android.domain.base.DataSourceType
import org.stepik.android.domain.certificate.repository.CertificateRepository
Expand All @@ -16,7 +16,7 @@ constructor(
private val certificateRepository: CertificateRepository,
private val courseRepository: CourseRepository
) {
fun getCertificates(userId: Long, page: Int = 1, sourceType: DataSourceType = DataSourceType.CACHE): Single<PagedList<CertificateViewItem>> =
fun getCertificates(userId: Long, page: Int = 1, sourceType: DataSourceType = DataSourceType.CACHE): Single<PagedList<CertificateListItem.Data>> =
certificateRepository.getCertificates(userId, page, sourceType)
.flatMap { certificates ->
val courseIds =
Expand All @@ -30,7 +30,7 @@ constructor(

PagedList(
certificates.map { certificate ->
CertificateViewItem(
CertificateListItem.Data(
certificate,
coursesMap[certificate.course]?.title,
coursesMap[certificate.course]?.cover
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.subscribeBy
import org.stepic.droid.di.qualifiers.BackgroundScheduler
import org.stepic.droid.di.qualifiers.MainScheduler
import org.stepic.droid.model.CertificateViewItem
import org.stepic.droid.model.CertificateListItem
import ru.nobird.android.core.model.PagedList
import ru.nobird.android.core.model.concatWithPagedList
import org.stepik.android.domain.base.DataSourceType
Expand Down Expand Up @@ -83,12 +83,12 @@ constructor(
oldState.certificates

oldState is CertificatesView.State.CertificatesCache ->
emptyList<CertificateViewItem>()
emptyList<CertificateListItem.Data>()

else -> return
}

val nextPage = (currentItems as? PagedList<CertificateViewItem>)
val nextPage = (currentItems as? PagedList<CertificateListItem.Data>)
?.page
?.plus(1)
?: 1
Expand Down Expand Up @@ -158,11 +158,11 @@ constructor(
.subscribeBy(
onSuccess = { updatedCertificate ->
val updatedItems = currentItems.transform {
map { certificateViewItem ->
if (certificateViewItem.certificate.id == updatedCertificate.id) {
certificateViewItem.copy(certificate = updatedCertificate)
map { certificateListItem ->
if (certificateListItem.certificate.id == updatedCertificate.id) {
certificateListItem.copy(certificate = updatedCertificate)
} else {
certificateViewItem
certificateListItem
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.stepik.android.presentation.certificate

import org.stepic.droid.model.CertificateViewItem
import org.stepic.droid.model.CertificateListItem
import org.stepik.android.model.Certificate
import ru.nobird.android.core.model.PagedList

Expand All @@ -11,9 +11,9 @@ interface CertificatesView {
object EmptyCertificates : State()
object NetworkError : State()

class CertificatesCache(val certificates: PagedList<CertificateViewItem>) : State()
class CertificatesRemote(val certificates: PagedList<CertificateViewItem>) : State()
class CertificatesRemoteLoading(val certificates: PagedList<CertificateViewItem>) : State()
class CertificatesCache(val certificates: PagedList<CertificateListItem.Data>) : State()
class CertificatesRemote(val certificates: PagedList<CertificateListItem.Data>) : State()
class CertificatesRemoteLoading(val certificates: PagedList<CertificateListItem.Data>) : State()
}

fun setState(state: State)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.stepik.android.presentation.profile_certificates

import org.stepic.droid.model.CertificateViewItem
import org.stepic.droid.model.CertificateListItem
import org.stepik.android.domain.profile.model.ProfileData

interface ProfileCertificatesView {
sealed class State {
object Idle : State()
object SilentLoading : State()
class Loading(val profileData: ProfileData) : State()
class CertificatesCache(val certificates: List<CertificateViewItem>, val profileData: ProfileData) : State()
class CertificatesRemote(val certificates: List<CertificateViewItem>, val profileData: ProfileData) : State()
class CertificatesCache(val certificates: List<CertificateListItem.Data>, val profileData: ProfileData) : State()
class CertificatesRemote(val certificates: List<CertificateListItem.Data>, val profileData: ProfileData) : State()
object Error : State()
object NoCertificates : State()
}
Expand Down
Loading

0 comments on commit 98ebcbf

Please sign in to comment.