NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

public class SplashViewModel extends ViewModel {

private final SharedPrefHelper helper;
private final SplashRepository splashRepository;

private String userId;
//Download text
private MutableLiveData<String> bannerDownloadText;
private MutableLiveData<String> leftDownloadText;
private MutableLiveData<String> rightDownloadText;

private int downloadIdBanner, downloadIdLeft, downloadIdRight;
private CompositeDisposable disposable;
private MutableLiveData<String> bannerContentStatus;
private MutableLiveData<String> leftContentStatus;
private MutableLiveData<String> rightContentStatus;
private ContentModel contentModel;
private String filePath;
//Download Percentage
private MutableLiveData<Integer> bannerPercent;
private MutableLiveData<Integer> leftPercent;
private MutableLiveData<Integer> rightPercent;

//Banner Content
private List<String> imageUrlBanner;
private List<String> fileNameBanner;
private List<String> getSizeOfFileBanner;

//Left Content
private List<String> imageUrlLeft;
private List<String> fileNameLeft;
private List<String> getSizeOfFileLeft;

//Right Content
private List<String> imageUrlRight;
private List<String> fileNameRight;
private List<String> getSizeOfFileRight;

private Context context;

@Inject
SplashViewModel(SharedPrefHelper helper, SplashRepository splashRepository) {

this.helper = helper;
this.splashRepository = splashRepository;
this.disposable = new CompositeDisposable();
imageUrlBanner = new ArrayList<>();
fileNameBanner = new ArrayList<>();
getSizeOfFileBanner = new ArrayList<>();
imageUrlLeft = new ArrayList<>();
fileNameLeft = new ArrayList<>();
getSizeOfFileLeft = new ArrayList<>();
imageUrlRight = new ArrayList<>();
fileNameRight = new ArrayList<>();
getSizeOfFileRight = new ArrayList<>();


userId = helper.get(USER_ID, "");
bannerContent();
leftContent();
rightContent();


}

public MutableLiveData<Integer> getBannerPercent() {
if (bannerPercent == null) {
bannerPercent = new MutableLiveData<>();
}
return bannerPercent;
}

public MutableLiveData<String> getBannerDownloadText() {
if (bannerDownloadText == null) {
bannerDownloadText = new MutableLiveData<>();
}
return bannerDownloadText;
}

public MutableLiveData<String> getBannerStatus() {
if (bannerContentStatus == null) {
bannerContentStatus = new MutableLiveData<>();
}
return bannerContentStatus;
}


public MutableLiveData<Integer> getLeftPercent() {
if (leftPercent == null) {
leftPercent = new MutableLiveData<>();
}
return leftPercent;
}

public MutableLiveData<String> getLeftDownloadText() {
if (leftDownloadText == null) {
leftDownloadText = new MutableLiveData<>();
}
return leftDownloadText;
}

public MutableLiveData<String> getLeftStatus() {
if (leftContentStatus == null) {
leftContentStatus = new MutableLiveData<>();
}
return leftContentStatus;
}


public MutableLiveData<Integer> getRightPercent() {
if (rightPercent == null) {
rightPercent = new MutableLiveData<>();
}
return rightPercent;
}

public MutableLiveData<String> getRightDownloadText() {
if (rightDownloadText == null) {
rightDownloadText = new MutableLiveData<>();
}
return rightDownloadText;
}

public MutableLiveData<String> getRightStatus() {
if (rightContentStatus == null) {
rightContentStatus = new MutableLiveData<>();
}
return rightContentStatus;
}


private void leftContent() {
splashRepository.getLeftContent(userId).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new SingleObserver<List<ContentModel>>() {
@Override
public void onSubscribe(Disposable d) {
disposable.add(d);
}

@Override
public void onSuccess(List<ContentModel> contentModels) {

Log.d("TAG", "onSuccess:" + new Gson().toJson(contentModels));
if (contentModels != null || !contentModels.isEmpty()) {
for (int i = 0; i < contentModels.size(); i++) {
if (contentModels.get(i).getImage() != null) {
fileNameLeft.add(contentModels.get(i).getImage()
.substring((contentModels.get(i).getImage().lastIndexOf("/") + 1)).trim());
imageUrlLeft.add(BASE_URL + contentModels.get(i).getImage());

insertIntoDB(contentModels, LEFT);
}
}
}

downloadLeftContent();

}

@Override
public void onError(Throwable e) {

}
});


}

private void downloadLeftContent() {
PRDownloaderConfig config = PRDownloaderConfig.newBuilder().setDatabaseEnabled(true).build();
PRDownloader.initialize(context, PRDownloaderConfig.newBuilder().build());

if (imageUrlLeft.size() <= 0) {
String leftStatus = "Downloaded";
leftContentStatus.setValue(leftStatus);
leftPercent.setValue(100);
leftDownloadText.setValue("3");

} else {
for (int i = 0; i < imageUrlLeft.size(); i++) {
File tempFile = new File(STORAGE_PATH_LEFT + fileNameLeft.get(i));

if (tempFile.exists()) {
getSizeOfFileLeft.add("a");
if (getSizeOfFileLeft.size() == imageUrlLeft.size()) {
String leftStatus = "Downloaded";
leftContentStatus.setValue(leftStatus);
leftPercent.setValue(100);
leftDownloadText.setValue("3");
}
} else {
downloadIdLeft = PRDownloader.download(imageUrlLeft.get(i), STORAGE_PATH_LEFT, fileNameLeft.get(i)).build()
.setOnStartOrResumeListener(() -> {
})
.setOnPauseListener(() ->
{
})
.setOnProgressListener(progress -> {
int percent = (int) progress.currentBytes * 100 / (int) progress.totalBytes;
String downloadText = ((int) progress.currentBytes * 3 / (int) progress.totalBytes) + "";
Log.d("TAG", "leftContentImage: " + percent);

leftPercent.setValue(percent);
leftDownloadText.setValue(downloadText);

})
.setOnCancelListener(() -> {
})
.start(new OnDownloadListener() {
@Override
public void onDownloadComplete() {
getSizeOfFileLeft.add("a");
if (getSizeOfFileLeft.size() == imageUrlLeft.size()) {
String leftStatus = "Downloaded";
leftContentStatus.setValue(leftStatus);

}
}


@Override
public void onError(Error error) {
PRDownloader.resume(downloadIdLeft);
}
});
}
}
}
}


private void rightContent() {
splashRepository.getRightContent(userId).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new SingleObserver<List<ContentModel>>() {
@Override
public void onSubscribe(Disposable d) {
disposable.add(d);
}

@Override
public void onSuccess(List<ContentModel> contentModels) {

Log.d("TAG", "onSuccess:" + new Gson().toJson(contentModels));

if (contentModels != null || !contentModels.isEmpty()) {
for (int i = 0; i < contentModels.size(); i++) {
if (contentModels.get(i).getImage() != null) {
fileNameRight.add(contentModels.get(i).getImage()
.substring((contentModels.get(i).getImage().lastIndexOf("/") + 1)).trim());
imageUrlRight.add(BASE_URL + contentModels.get(i).getImage());

insertIntoDB(contentModels, RIGHT);
}
}
}
downloadRightImage();

}

@Override
public void onError(Throwable e) {

}
});
}

private void downloadRightImage() {
PRDownloaderConfig config = PRDownloaderConfig.newBuilder().setDatabaseEnabled(true).build();
PRDownloader.initialize(context, PRDownloaderConfig.newBuilder().build());

if (imageUrlRight.size() <= 0) {
String rightStatus = "Downloaded";
rightContentStatus.setValue(rightStatus);
rightPercent.setValue(100);
rightDownloadText.setValue("3");

} else {
for (int i = 0; i < imageUrlRight.size(); i++) {
File tempFile = new File(STORAGE_PATH_RIGHT + fileNameRight.get(i));

if (tempFile.exists()) {
getSizeOfFileRight.add("a");
if (getSizeOfFileRight.size() == imageUrlRight.size()) {
String rightStatus = "Downloaded";
rightContentStatus.setValue(rightStatus);
rightPercent.setValue(100);
rightDownloadText.setValue("3");
}
} else {
//final int finalI = i;
downloadIdRight = PRDownloader.download(imageUrlRight.get(i), STORAGE_PATH_RIGHT, fileNameRight.get(i)).build()
.setOnStartOrResumeListener(() -> {
Log.d("TAG", "startImageDownload: ");
}).setOnPauseListener(() -> {

}).setOnProgressListener(progress -> {
int percent = (int) progress.currentBytes * 100 / (int) progress.totalBytes;
String downloadText = ((int) progress.currentBytes * 3 / (int) progress.totalBytes) + "";

Log.d("TAG", "rightContentImage: " + percent);
rightPercent.setValue(percent);
rightDownloadText.setValue(downloadText);

}).start(new OnDownloadListener() {
@Override
public void onDownloadComplete() {
Log.d("TAG", "onDownloadComplete: " + " ");
getSizeOfFileRight.add("a");
if (getSizeOfFileRight.size() == imageUrlRight.size()) {
String rightStatus = "Downloaded";
rightContentStatus.setValue(rightStatus);
}
}

@Override
public void onError(Error error) {
PRDownloader.resume(downloadIdRight);


}
});
}
}
}
}


private void bannerContent() {
splashRepository.getBannerContent(userId).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new SingleObserver<List<ContentModel>>() {
@Override
public void onSubscribe(Disposable d) {
disposable.add(d);
}

@Override
public void onSuccess(List<ContentModel> contentModels) {
Log.d("TAG", "Check" + new Gson().toJson(contentModels));

if (contentModels != null || !contentModels.isEmpty()) {
for (int i = 0; i < contentModels.size(); i++) {
if (contentModels.get(i).getImage() != null) {
fileNameBanner.add(contentModels.get(i).getImage()
.substring((contentModels.get(i).getImage().lastIndexOf("/") + 1)).trim());
imageUrlBanner.add(BASE_URL + contentModels.get(i).getImage());

insertIntoDB(contentModels, BANNER);
}
}
}
bannerContentImage();


}

@Override
public void onError(Throwable e) {
Log.e("SPLASH", "onError: BANNER ERROR", e);

}
});
}

private void bannerContentImage() {
PRDownloaderConfig config = PRDownloaderConfig.newBuilder().setDatabaseEnabled(true).build();
PRDownloader.initialize(context, PRDownloaderConfig.newBuilder().build());

if (imageUrlBanner.size() <= 0) {
String bannerStatus = "Downloaded";
bannerContentStatus.setValue(bannerStatus);
bannerPercent.setValue(100);
bannerDownloadText.setValue("3");

} else {
for (int i = 0; i < imageUrlBanner.size(); i++) {
File tempFile = new File(STORAGE_PATH_BANNER + fileNameBanner.get(i));

if (tempFile.exists()) {
getSizeOfFileBanner.add("a");
if (getSizeOfFileBanner.size() == imageUrlBanner.size()) {
String bannerStatus = "Downloaded";
bannerContentStatus.setValue(bannerStatus);
bannerDownloadText.setValue("3");
}
} else {
//final int finalI = i;

downloadIdBanner = PRDownloader.download(imageUrlBanner.get(i), STORAGE_PATH_BANNER, fileNameBanner.get(i)).build()
.setOnStartOrResumeListener(() -> {
Log.d("TAG", "startImageDownload: ");
}).setOnPauseListener(() -> {

}).setOnProgressListener(progress -> {

int percent = (int) progress.currentBytes * 100 / (int) progress.totalBytes;
String downloadText = ((int) progress.currentBytes * 3 / (int) progress.totalBytes) + "";
Log.d("TAG", "bannerContentImage: " + percent);
bannerPercent.setValue(percent);
bannerDownloadText.setValue(downloadText);
}).start(new OnDownloadListener() {
@Override
public void onDownloadComplete() {
getSizeOfFileBanner.add("a");
if (getSizeOfFileBanner.size() == imageUrlBanner.size()) {
String bannerStatus = "Downloaded";
bannerContentStatus.setValue(bannerStatus);

Log.d("TAG", "BannerStatus" + bannerStatus);
}

}

@Override
public void onError(Error error) {
PRDownloader.resume(downloadIdBanner);

}

});
}
}
}
}

private void insertIntoDB(List<ContentModel> contentModels, String contentType) {
for (ContentModel contentModel : contentModels) {
if (contentModel.getImage() != null) {
String filename = contentModel.getImage().substring(contentModel.getImage().lastIndexOf("/") + 1)
.trim();
switch (contentType) {
case BANNER:
filePath = STORAGE_PATH_BANNER + filename;
break;
case LEFT:
filePath = STORAGE_PATH_LEFT + filename;
break;
case RIGHT:
filePath = STORAGE_PATH_RIGHT + filename;
break;
}
contentModel.setUserId(userId);
contentModel.setFilePath(filePath);
contentModel.setEffect(contentModel.getEffect());
contentModel.setTime(contentModel.getTime());
contentModel.setCaption(contentModel.getCaption());
contentModel.setFit(contentModel.getFit());
contentModel.setContentType(contentType);
splashRepository.insertIntoDb(contentModel);

} else if (contentModel.getText() != null) {
contentModel.setUserId(userId);
contentModel.setFilePath(filePath);
contentModel.setEffect(contentModel.getEffect());
contentModel.setTime(contentModel.getTime());
contentModel.setCaption(contentModel.getCaption());
contentModel.setFit(contentModel.getFit());
contentModel.setContentType(contentType);

splashRepository.insertIntoDb(contentModel);
}
}
}

}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.