Search in sources :

Example 1 with UploadItem

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);
}
Also used : LayoutAnimationController(android.view.animation.LayoutAnimationController) List(java.util.List) UploadHistoryListAdapter(com.thecoolguy.rumaan.fileio.adapters.UploadHistoryListAdapter) UploadItem(com.thecoolguy.rumaan.fileio.data.models.UploadItem) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ActionBar(android.support.v7.app.ActionBar) UploadItemViewModel(com.thecoolguy.rumaan.fileio.data.UploadItemViewModel)

Example 2 with UploadItem

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());
    }
}
Also used : UploadItem(com.thecoolguy.rumaan.fileio.data.models.UploadItem)

Example 3 with UploadItem

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);
    }
}
Also used : UploadItem(com.thecoolguy.rumaan.fileio.data.models.UploadItem) Before(org.junit.Before)

Example 4 with 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));
}
Also used : UploadItem(com.thecoolguy.rumaan.fileio.data.models.UploadItem) Test(org.junit.Test)

Example 5 with UploadItem

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);
        }
    });
}
Also used : Request(com.github.kittinunf.fuel.core.Request) Function2(kotlin.jvm.functions.Function2) URL(java.net.URL) Response(com.github.kittinunf.fuel.core.Response) FuelError(com.github.kittinunf.fuel.core.FuelError) UploadItem(com.thecoolguy.rumaan.fileio.data.models.UploadItem) File(java.io.File) Pair(kotlin.Pair)

Aggregations

UploadItem (com.thecoolguy.rumaan.fileio.data.models.UploadItem)6 Test (org.junit.Test)2 ActionBar (android.support.v7.app.ActionBar)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 LayoutAnimationController (android.view.animation.LayoutAnimationController)1 FuelError (com.github.kittinunf.fuel.core.FuelError)1 Request (com.github.kittinunf.fuel.core.Request)1 Response (com.github.kittinunf.fuel.core.Response)1 UploadHistoryListAdapter (com.thecoolguy.rumaan.fileio.adapters.UploadHistoryListAdapter)1 UploadItemViewModel (com.thecoolguy.rumaan.fileio.data.UploadItemViewModel)1 File (java.io.File)1 URL (java.net.URL)1 List (java.util.List)1 Pair (kotlin.Pair)1 Function2 (kotlin.jvm.functions.Function2)1 Before (org.junit.Before)1