-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #54: The app requires the user name when he enter in session
fix #54 When the user open the Session Activity (after create a new session or when it click on a shared link) the app will check if there are an user on shared preferences. If there is not any, the app will require a name
- Loading branch information
1 parent
55c6da2
commit 03c6ec6
Showing
21 changed files
with
353 additions
and
58 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...va/br/org/cesar/discordtime/stickysessions/data/local/repository/UserLocalRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package br.org.cesar.discordtime.stickysessions.data.local.repository; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
|
||
import br.org.cesar.discordtime.stickysessions.domain.repository.UserRepository; | ||
import io.reactivex.Single; | ||
import io.reactivex.SingleEmitter; | ||
import io.reactivex.SingleOnSubscribe; | ||
|
||
public class UserLocalRepository implements UserRepository { | ||
|
||
private static final String USER_KEY = "user"; | ||
|
||
private final Context mContext; | ||
private final String mSharedPrefs; | ||
|
||
public UserLocalRepository(Context context, String sharedPrefsName) { | ||
mContext = context; | ||
mSharedPrefs = sharedPrefsName; | ||
} | ||
|
||
@Override | ||
public Single<Boolean> saveUser(String user) { | ||
return Single.create(emitter -> { | ||
SharedPreferences prefs = | ||
mContext.getSharedPreferences(mSharedPrefs, Context.MODE_PRIVATE); | ||
SharedPreferences.Editor editor = prefs.edit(); | ||
editor.putString(USER_KEY, user); | ||
|
||
if (editor.commit()) { | ||
emitter.onSuccess(true); | ||
} else { | ||
emitter.onError( | ||
new Exception("The user could not be saved into local repository") | ||
); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public Single<String> getSavedUser() { | ||
return Single.create(emitter -> { | ||
SharedPreferences prefs = | ||
mContext.getSharedPreferences(mSharedPrefs, Context.MODE_PRIVATE); | ||
String userSaved = prefs.getString(USER_KEY, null); | ||
if (userSaved != null) { | ||
emitter.onSuccess(userSaved); | ||
} else { | ||
emitter.onError(new Exception("User Not found")); | ||
} | ||
|
||
|
||
}); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...src/main/java/br/org/cesar/discordtime/stickysessions/domain/interactor/GetLocalUser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package br.org.cesar.discordtime.stickysessions.domain.interactor; | ||
|
||
import br.org.cesar.discordtime.stickysessions.domain.repository.UserRepository; | ||
import io.reactivex.Single; | ||
import io.reactivex.SingleObserver; | ||
|
||
public class GetLocalUser extends UseCase<Void,String> { | ||
|
||
private final UserRepository mUserRepository; | ||
|
||
public GetLocalUser(UserRepository repository) { | ||
mUserRepository = repository; | ||
} | ||
|
||
@Override | ||
public Single<String> execute(Void params) { | ||
return mUserRepository.getSavedUser(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
.../main/java/br/org/cesar/discordtime/stickysessions/domain/interactor/SaveCurrentUser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package br.org.cesar.discordtime.stickysessions.domain.interactor; | ||
|
||
import br.org.cesar.discordtime.stickysessions.domain.repository.UserRepository; | ||
import io.reactivex.Single; | ||
|
||
public class SaveCurrentUser extends UseCase<String, Boolean> { | ||
|
||
private UserRepository mUserRepository; | ||
|
||
public SaveCurrentUser(UserRepository userRepository) { | ||
mUserRepository = userRepository; | ||
} | ||
|
||
@Override | ||
public Single<Boolean> execute(String userName) { | ||
|
||
if (userName == null || userName.trim().isEmpty()) { | ||
return Single.error(new Exception("The user is invalid (null or empty)")); | ||
} | ||
|
||
return mUserRepository.saveUser(userName); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/br/org/cesar/discordtime/stickysessions/domain/model/NoteFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package br.org.cesar.discordtime.stickysessions.domain.model; | ||
|
||
public class NoteFilter { | ||
|
||
public String user; | ||
public String idSession; | ||
|
||
public NoteFilter(String idSession, String user) { | ||
this.user = user; | ||
this.idSession = idSession; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...c/main/java/br/org/cesar/discordtime/stickysessions/domain/repository/UserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package br.org.cesar.discordtime.stickysessions.domain.repository; | ||
|
||
import io.reactivex.Single; | ||
|
||
public interface UserRepository { | ||
Single<Boolean> saveUser(String user); | ||
Single<String> getSavedUser(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
app/src/main/java/br/org/cesar/discordtime/stickysessions/injectors/modules/UserModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package br.org.cesar.discordtime.stickysessions.injectors.modules; | ||
|
||
import android.content.Context; | ||
|
||
import javax.inject.Named; | ||
|
||
import br.org.cesar.discordtime.stickysessions.data.local.repository.UserLocalRepository; | ||
import br.org.cesar.discordtime.stickysessions.domain.interactor.GetLocalUser; | ||
import br.org.cesar.discordtime.stickysessions.domain.interactor.SaveCurrentUser; | ||
import br.org.cesar.discordtime.stickysessions.domain.repository.UserRepository; | ||
import br.org.cesar.discordtime.stickysessions.executor.ObservableUseCase; | ||
import br.org.cesar.discordtime.stickysessions.executor.PostExecutionThread; | ||
import br.org.cesar.discordtime.stickysessions.executor.ThreadExecutor; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
|
||
@Module | ||
public class UserModule { | ||
|
||
@Provides | ||
public ObservableUseCase<String, Boolean> providesObservableSaveCurrentUser( | ||
SaveCurrentUser saveCurrentUser, | ||
ThreadExecutor threadExecutor, | ||
PostExecutionThread postExecutionThread) { | ||
return new ObservableUseCase<>(saveCurrentUser, threadExecutor, postExecutionThread); | ||
} | ||
|
||
@Provides | ||
public ObservableUseCase<Void, String> providesObservableGetSavedUser( | ||
GetLocalUser getLocalUser, ThreadExecutor threadExecutor, | ||
PostExecutionThread postExecutionThread) { | ||
|
||
return new ObservableUseCase<>(getLocalUser, threadExecutor, postExecutionThread); | ||
} | ||
|
||
@Provides | ||
public SaveCurrentUser providesSaveCurrentUser(UserRepository repository) { | ||
return new SaveCurrentUser(repository); | ||
} | ||
|
||
@Provides | ||
public GetLocalUser providesGetLocalUser(UserRepository repository) { | ||
return new GetLocalUser(repository); | ||
} | ||
|
||
@Provides | ||
public UserRepository providesUserRepository(Context context, @Named("prefs") String prefsName) { | ||
return new UserLocalRepository(context, prefsName); | ||
} | ||
|
||
@Provides | ||
@Named("prefs") | ||
public String providesPreferenceName() { | ||
return "user_preference"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.