Skip to content

Instantly share code, notes, and snippets.

@aemxn
aemxn / dl_image.py
Created Oct 20, 2020
Download image with interval
View dl_image.py
import requests
import shutil
import time
import time
import threading
def dl():
image_url = "https://p3.fgies.com/bucket-pnb/PNB-11.jpg"
filename_jpeg = image_url.split("/")[-1]
filename_ts = filename_jpeg.split(".")[0]
@aemxn
aemxn / android-mvp-architecture.md
Created Jul 10, 2020
Android MVP Architecture
View android-mvp-architecture.md

Android MVP Architecture

0. What is an MVP?

MVP is a Model-View-Presenter in short. It is a derivative from Model-View-Controller (MVC) software architectural pattern. The main concern about MVP structure is that it separates the view from the backend logic. Because Android [doesn't care][1] about which pattern to be used when developing, the community developer itself has to debate on which architecture to use.

It is well suited in Android because we needed it for easy testability, at least that's what I see when developing an app based on this structure. Just to let you know, this article only covers on how to implement the layering structure WITHOUT testing suite and dependency injection.

It is gonna be plain and simple to understand how it works under the hood. You can structure it any way you want but the basic idea is that view updates "decision" is done by the Presenter via View.

@aemxn
aemxn / open-source-imageboard
Created Dec 11, 2019
Open source imageboard
View open-source-imageboard
https://github.com/kennell/imageboards
https://github.com/blobmon/simplechan
https://gitgud.io/LynxChan/LynxChan
https://github.com/VVatashi/TinyIB
https://github.com/bakape/meguca
https://github.com/lalcmellkmal/doushio
https://github.com/underr/shoganai
https://github.com/sougai/chakai
https://github.com/vampiricwulf/ex-tanoshiine
https://github.com/praetorg/uchan
@aemxn
aemxn / BasePresenter.java
Created Aug 24, 2017
Presenter base class
View BasePresenter.java
public abstract class BasePresenter<V extends RemoteView> {
private WeakReference<V> view = null;
public final void attachView(V view) {
if (view == null) throw new NullPointerException("View must not be null");
if(this.view != null) detachView(this.view.get());
this.view = new WeakReference<V>(view);
View LoginActivity.java
package com.myapp.ui.home;
public class LoginActivity extends BaseActivity implements LoginContract.LoginView {
// field declaration
private LoginPresenter presenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
@aemxn
aemxn / LoginRepositoryImpl.java
Created Aug 23, 2017
Implementation for LoginRepository
View LoginRepositoryImpl.java
package com.myapp.core.data.repository.impl;
public class LoginRepositoryImpl implements Repository<Login> {
private DatabaseRealm databaseRealm;
public LoginRepositoryImpl(DatabaseRealm databaseRealm) {
this.databaseRealm = databaseRealm;
}
@aemxn
aemxn / Repository.java
Created Aug 23, 2017
Repository interface base class
View Repository.java
public interface Repository<T> {
T find(String guid);
List<T> findAll();
void add(T item);
void add(List<T> items);
@aemxn
aemxn / RemoteView.java
Created Aug 23, 2017
Generic view base class
View RemoteView.java
public interface RemoteView {
void showProgress();
void hideProgress();
void showUnauthorizedError();
void showEmpty();
View LoginPresenter.java
package com.myapp.core.mvp.home.login;
public class LoginPresenter extends BasePresenter<LoginContract.LoginView> implements LoginContract.ViewAction {
private APIManager apiManager;
private PreferenceService preference;
private INetworkManager networkManager;
private Repository<Login> eventRepository;
public LoginPresenter(APIManager apiManager, PreferenceService preference,
View LoginContract.java
package com.myapp.core.mvp.home.login;
public interface LoginContract {
interface ViewAction{
void onUserLogin(@NonNull Login login);
}
interface LoginView extends RemoteView {
void onLoginSuccess();