use of com.thecoolguy.rumaan.fileio.data.models.UploadItem in project file.io-app by rumaan.
the class UploadHistoryActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload_history);
ButterKnife.bind(this);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(getString(R.string.upload_history_title));
actionBar.setDisplayHomeAsUpEnabled(true);
}
final UploadHistoryListAdapter uploadHistoryListAdapter = new UploadHistoryListAdapter(this);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(linearLayoutManager);
uploadItemViewModel = ViewModelProviders.of(this).get(UploadItemViewModel.class);
uploadItemViewModel.getUploadHistoryList().observe(this, new Observer<List<UploadItem>>() {
@Override
public void onChanged(@Nullable List<UploadItem> uploadItems) {
if ((uploadItems == null) || uploadItems.isEmpty()) {
noUploadsView.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.INVISIBLE);
} else {
noUploadsView.setVisibility(View.INVISIBLE);
recyclerView.setVisibility(View.VISIBLE);
uploadHistoryListAdapter.setUploadItemList(uploadItems);
recyclerView.addItemDecoration(getSectionCallback(uploadItemViewModel.getUploadHistoryList().getValue()));
}
}
});
recyclerView.setAdapter(uploadHistoryListAdapter);
uploadHistoryListAdapter.setOnUploadItemLongClickListener(this);
LayoutAnimationController layoutAnimationController = AnimationUtils.loadLayoutAnimation(this, R.anim.layout_anim_fall_down);
recyclerView.setLayoutAnimation(layoutAnimationController);
}
use of com.thecoolguy.rumaan.fileio.data.models.UploadItem in project file.io-app by rumaan.
the class UploadHistoryListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
if (uploadItemList != null) {
UploadItem uploadItem = uploadItemList.get(position);
holder.fileName.setText(uploadItem.getFileName());
holder.fileUrl.setText(uploadItem.getUrl());
}
}
use of com.thecoolguy.rumaan.fileio.data.models.UploadItem in project file.io-app by rumaan.
the class UploadHistoryInstrumentedTest method init.
@Before
public void init() {
database = Room.inMemoryDatabaseBuilder(InstrumentationRegistry.getContext(), UploadHistoryRoomDatabase.class).build();
// add five items into the database
for (int i = 0; i < 5; i++) {
UploadItem uploadItem = new UploadItem("test file name " + i, "test URL " + i, DateUtil.getTimeStamp(), Consts.DEFAULT_EXPIRE_WEEKS);
database.uploadItemDao().insert(uploadItem);
}
}
use of com.thecoolguy.rumaan.fileio.data.models.UploadItem in project file.io-app by rumaan.
the class UploadItemDaoTest method check_InsertUploadItemSaves.
@Test
public void check_InsertUploadItemSaves() {
UploadItem uploadItem = new UploadItem("test", "test", DateUtil.getTimeStamp(), 2);
// check for nulls in the upload item object
assertNotNull(uploadItem);
assertEquals("test", uploadItem.getFileName());
assertEquals("test", uploadItem.getUrl());
// check for nulls in database object
assertNotNull(database);
long id = database.uploadItemDao().insert(uploadItem);
assertNotNull(id);
// retrieve from the DB
assertNotNull(database.uploadItemDao().getItem(id));
}
use of com.thecoolguy.rumaan.fileio.data.models.UploadItem in project file.io-app by rumaan.
the class UploadRepository method uploadFile.
void uploadFile(final FileModel fileModel, final Upload resultCallback) {
final File file = fileModel.getFile();
// create an upload item from the file model
final UploadItem uploadItem = new UploadItem();
uploadItem.setFileName(file.getName());
// set up query parameters
// NOTE: here getDaysToExpire() actually returns the number of weeks selected by the user.
String link = "https://file.io/?expires=" + fileModel.getDaysToExpire();
Log.i(TAG, "Request Link: " + link);
// TODO: change the file object to InputStream
Fuel.upload(link).source(new Function2<Request, URL, File>() {
@Override
public File invoke(Request request, URL url) {
return file;
}
}).name(new Function0<String>() {
@Override
public String invoke() {
return "file";
}
}).progress(new Function2<Long, Long, Unit>() {
@Override
public Unit invoke(Long bytesUploaded, Long totalBytes) {
int p = (int) (((float) bytesUploaded / totalBytes) * 100);
resultCallback.progress(p);
return null;
}
}).responseString(new Handler<String>() {
@Override
public void success(Request request, Response response, String res) {
// Parse the JSON from the response.
Pair<String, Integer> parsedResults = getParsedResults(res);
if (parsedResults != null) {
// Set the URL
uploadItem.setUrl(parsedResults.getFirst());
// Set the Days after which the link will expire
uploadItem.setDaysToExpire(parsedResults.getSecond());
// Set the upload time
uploadItem.setDate(getCurrentDate());
// Insert the Object intro the Database
insert(uploadItem);
// Pass out the received upload link to listeners
resultCallback.onUpload(parsedResults.getFirst());
} else {
failure(request, response, new FuelError(new NullPointerException("Data formed from JSON maybe was null."), null, response));
}
}
@Override
public void failure(Request request, Response response, FuelError fuelError) {
Crashlytics.logException(fuelError);
Log.e(TAG, "failure: " + fuelError.getMessage(), fuelError.getException());
resultCallback.onError(fuelError);
}
});
}
Aggregations